0

Within a web form I am dynamically creating a series of chekboxes that are added to an asp:panel.Where as the panel in reside into a update panel.I want to avoid postback on checkbox changed event fire.

my code snippet:

Aspx code:

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
  <ContentTemplate>
     <asp:Panel ID="pnlCuisine" runat="server"></asp:Panel>
  </ContentTemplate>

C# Code:

public static CheckBox[] chkbx = new CheckBox[15];
public static Label[] lblCuisine = new Label[15];
private void LoadCuisine(string searchStr)
    {
      .....
      .....
      .....
            int i = 1;

            foreach(var item in cuisineList)
            {
                chkbx[i]=new CheckBox();
                chkbx[i].ID = item.CategoryName;
                chkbx[i].Text = item.CategoryName;
                chkbx[i].AutoPostBack = true;

                lblCuisine[i] = new Label();
                lblCuisine[i].ID = "lblCuisine" + Convert.ToString(i);
                lblCuisine[i].Text = "(" + item.Count + ")";

                chkbx[i].CheckedChanged += new EventHandler(chkbx_CheckedChanged);

                pnlCuisine.Controls.Add(chkbx[i]);
                pnlCuisine.Controls.Add(lblCuisine[i]);
               pnlCuisine.Controls.Add(new LiteralControl("<br/>"));
                i++;
            }
}
   void chkbx_CheckedChanged(object sender, EventArgs e)
    {
        string searchString = ((CheckBox)sender).ClientID;
        populateGrid(searchString);
    }
4

1 回答 1

0

请更改这行代码

chkbx[i].AutoPostBack = true;

chkbx[i].AutoPostBack = false;

那么您可以避免在复选框更改事件触发时自动回发

于 2013-05-25T11:16:17.800 回答