好吧,儘可能簡單,我有一個checkboxlist設置爲true和OnSelectedIndexChanged的autopostback。但是,每次有人點擊複選框中的項目時,頁面都會刷新。我該如何阻止?我試過使用UpdatedPanel(這是一種工作)。如何停止頁面刷新每次複選框是單擊
<asp:CheckBoxList ID="Regions" runat="server" OnSelectedIndexChanged="Regions_SelectedIndexChanged" AutoPostBack="true" DataSourceID="SqlDataSource2" DataTextField="Regions" DataValueField="ID">
</asp:CheckBoxList>
OnselectedIndexChange顯示一個複選框旁邊的其他複選框的div。
protected void Regions_SelectedIndexChanged(object sender, EventArgs e)
{
string select = @"Select Facilities from [BulletinBoard].[DMHSAS\290974].[Facilities] ";
int[] ctr = new int[9];
int ctr1 = 0;
int counter = 0;
dFacilities.Style.Add("display", "block");
foreach (ListItem item in Regions.Items)
{
//Response.Write(item.Selected);
if (Regions.SelectedIndex == 0)
{
item.Selected = true;
CheckBoxList1.Visible = true;
counter++;
}
else if (item.Selected)
{
if (select.EndsWith("[Facilities] "))
{
select += "where ";
}
if (select.EndsWith(") "))
{
select += " or ";
}
select += " (Reg_ID = " + Regions.SelectedIndex + ") ";
ctr[ctr1 + 1] = Regions.SelectedIndex;
item.Selected = false;
counter++;
CheckBoxList1.Visible = true;
}
ctr1++;
}
if (counter == 0)
{
CheckBoxList1.Visible = false;
dFacilities.Style.Add("display", "none");
}
ctr1 = 0;
bool all = false;
foreach (int counter1 in ctr)
{
Regions.Items[counter1].Selected = true;
if (Regions.Items[0].Selected == true)
foreach (ListItem item in Regions.Items)
{
if (item.Selected)
{
all = true;
}
else
{
all = false;
break;
}
}
if (all == false)
{
Regions.Items[0].Selected = false;
}
}
所以它與'UpdatePanel'工作或沒有?無論如何你還沒有展示過它。 – 2014-09-02 20:36:21
OP說使用updatepanel它的工作方式! – rach 2014-09-02 20:41:49
'UpdatePanel'只是簡單的屏蔽了頁面刷新。你還在做回發。如果你不想刷新頁面,爲什麼不把'autopostback'設置爲'false'? – Mrchief 2014-09-02 20:43:15