避免在asp.net c中回发动态创建的复选框#

时间:2013-05-25 11:13:19

标签: c# asp.net checkbox

在Web表单中,我动态创建了一系列添加到asp:panel的chekbox。当面板驻留在更新面板中时。我想避免在复选框更改事件触发时回发。

我的代码段:

Aspx代码:

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

C#代码:

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

1 个答案:

答案 0 :(得分:0)

请更改此行代码

chkbx[i].AutoPostBack = true;

chkbx[i].AutoPostBack = false;

然后你可以避免自动回复复选框更改的事件火灾