Benoît S
Benoît S

Reputation: 163

CheckBoxlist Updating a dropdowlist in UpdatePanel no longer PostBack

I need to Update a Dropdowlist according to the selected value(s) in a CheckBoxList avoiding the page to reload, I am using an UpdatePanel. The dropdwonlist should always have an AutoPostback, it should always trigger my "SearchEvent"

I used an UpdatePanel and an AsyncPostBackTrigger on my CheckBoxlist to call the function in code behind to refresh the dropdowlist.

It works only one time. After the first call, I cannot trigger the CheckBoxlist SelectedIndexChanged, instead I get the error :

"Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 404"

My dropdownlist also lose the PostBack, nothing happens.

The 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>

My code behind :

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();
    }

When I change the IsActiveFilterCheck checkboxlist I should update only the StatusFilterList as shown in the function IsActiveFilterCheck_Changed, without reloading the full page.

This StatusFilterList should always be able to call/Trigger the event SearchButton_ServerClick

Right now It works only one time when the IsActiveFilterCheck is fired my dropdowlist is updated but after when I click anywhere I get the error and I can't trigger the IsActiveFilterCheck

Upvotes: 0

Views: 268

Answers (1)

Mr.Deer
Mr.Deer

Reputation: 476

Take a look to this :

AsyncPostBackTrigger works only the first time

People usually recreates the trigger to work after first time.

Upvotes: 1

Related Questions