我需要根据CheckBoxList中的选定值更新Dropdowlist,以避免重新加载页面,我正在使用UpdatePanel。 dropdwonlist应该始终具有AutoPostback,它应该始终触发我的“ SearchEvent”
我在CheckBoxlist上使用了UpdatePanel和AsyncPostBackTrigger来调用后面的代码中的函数以刷新下拉列表。
它只能运行一次。第一次通话后,我无法触发CheckBoxlist SelectedIndexChanged,而是出现错误:
“ Sys.WebForms.PageRequestManagerServerErrorException:在服务器上处理请求时发生未知错误。服务器返回的状态码为:404”
我的下拉列表也丢失了回发,什么也没发生。
View ASPX:
<td>
<asp:ScriptManager ID="ScriptManager" runat="server" />
<asp:CheckBoxList ID="IsActiveFilterCheck" runat="server" AutoPostBack="true" AppendDataBoundItems="true" CausesValidation="False">
<asp:ListItem Text="Active" Value="1" />
<asp:ListItem Text="Closed" Value="0" />
</asp:CheckBoxList>
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel1" ChildrenAsTriggers="true" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="IsActiveFilterCheck" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<br /><br />
<asp:DropDownList ID="StatusFilterList" runat="server" DataTextField="Name" DataValueField="Id">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
我后面的代码:
private void Page_Load(object sender, System.EventArgs e)
{
RegisterCallbacks();
if (!IsPostBack)
{
Initialize();
}
}
override protected void OnInit(EventArgs e)
{
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
CheckProfil();
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.SearchButton.ServerClick += new System.EventHandler(this.SearchButton_ServerClick);
this.StatusFilterList.SelectedIndexChanged += new System.EventHandler(this.SearchButton_ServerClick);
this.IsActiveFilterCheck.SelectedIndexChanged += new System.EventHandler(this.IsActiveFilterCheck_Changed);
this.Load += new System.EventHandler(this.Page_Load);
}
protected void IsActiveFilterCheck_Changed(object sender, EventArgs e)
{
// Update the Status Filter List
StatusFilterList.Items.Clear();
if (IsActiveFilterCheck.Items.Cast<ListItem>().Where(li => li.Selected).ToList().Count != 1)
{
BindListInsertAll(StatusFilterList, ExpectedStatusCollection.Instance.GetAll());
}
else
{
IList statusSelected = ExpectedStatusCollection.Instance
.GetAll().Cast<ExpectedStatusDo>()
.Where(exp => IsActiveFilterCheck.SelectedValue == "1" ? exp.Id != 5 && exp.Id != 6 : exp.Id == 5 || exp.Id == 6)
.ToList(); // Only Dead and Signed
// Update the Status
BindListInsertAll(StatusFilterList, statusSelected);
}
UpdatePanel1.Update();
//FindByFilter();
}
当我更改 IsActiveFilterCheck 复选框时,应仅更新 StatusFilterList ,如功能 IsActiveFilterCheck_Changed 所示,而无需重新加载整个页面。 / p>
此 StatusFilterList 应该始终能够调用/触发事件 SearchButton_ServerClick
现在,当启动 IsActiveFilterCheck 时,我的dropdowlist只会被更新一次,但是当我单击任何地方后,我都会收到错误消息,并且无法触发 IsActiveFilterCheck