开发者

ASP.NET UpdatePanel > Get selected value from checbox list outside of panel

开发者 https://www.devze.com 2022-12-24 18:36 出处:网络
I have a listing in an UpdatePanel I have some filters for that list in the form a checkboxList control.

I have a listing in an UpdatePanel

I have some filters for that list in the form a checkboxList control. The checkboxList is created dynamically on page load

During the Ajax update (postback), the checkbox list is not populated form the viewstate, so I cannot get the listing to filte开发者_StackOverflow中文版r.

Note: If I put the checkbox list items directly in the markup, it all works, just not if the listing is populated on-postback.

protected override void OnLoad(EventArgs e)
{
    if (!Page.IsPostBack)
    {
        foreach (var p in global.Product)
            CheckListManufacurer.Items.Add(new ListItem(p, p));
    }
    base.OnLoad(e);
}


<form id="ProductListForm" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
  <asp:CheckBoxList ID="CheckListManufacurer" runat="server" EnableViewState="true">
     <asp:ListItem Value="" Text="(All)"></asp:ListItem>
  </asp:CheckBoxList>  
  <asp:Button id="btnTestAjax" runat="server" Text="Test" />  
  <asp:UpdatePanel ID="ProductsPanel" runat="server" UpdateMode="Conditional">
      <Triggers>
          <asp:AsyncPostBackTrigger ControlID="btnTestAjax"  />
          <asp:AsyncPostBackTrigger ControlID="CheckListManufacurer" />
      </Triggers>
      <ContentTemplate>
          <sr:ProductList ID="Products" runat="server" />
      </ContentTemplate>
  </asp:UpdatePanel>
</form>


if you populate the list in Page_Load then you're too late.

in the asp.net page event lifecycle viewstate is populated just before Page_PreLoad (see here: http://msdn.microsoft.com/en-us/library/ms178472.aspx )

so if you want viewstate to be loaded into controls you dynamically add to the page you need to add them in Page_Init

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号