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