I Dynamic generate checkbox control.
In Process control function my checkbox is always false (chk.Checked).
Why my Checkbox check state is loss.
Please give me proper solution of this.
protected void Page_Load(object sender, EventArgs e)
{
PopulateLeftSearchPane();
}
PopulateLeftSearchPane()
{
UpdatePanel myupdpnl = new UpdatePanel();
myupdpnl.ID = "upnl" + cn.AspectID + "_" + cn.TraitID;
CheckBox chk = new CheckBox();
chk.ID = "chktrait" + cn.AspectID + "_" + cn.TraitID;
chk.Text = cn.ValueName;
chk.Attributes.Add("AspectID", cn.AspectID.ToString());
chk.Attributes.Add("TraitID", cn.TraitID.ToString());
chk.AutoPostBack = false;
chk.Attributes.Add("onchange", "Javascript:return CallSearchResults('" + chk.ID + "','" + cn.AspectID + "','" + cn.TraitID + "','" + cn.ValueName + "'" + ");");
myupdpnl.ContentTemplateContainer.Controls.Add(chk);
divaccordioninner.Controls.Add(myupdpnl);
}
protected void btnSearchResult_Click(object sender, EventArgs e)
{
ProcessControls(divLeftpane,false);
}
private void ProcessControls(Control ctrlContainer, bool Isall)
{
foreach (Control ctrl in ctrlContainer.Controls)
{
if (ctrl.GetType() == typeof(TextBox))
{
}
else if (ctrl.GetType() == typeof(CheckBox))
{
CheckBox chk = (CheckBox)ctrl;
if (Isall == false)
{
if (chk.Checked)
{
Int64 intAspectID = Convert.ToInt64(chk.Attributes["AspectID"]);
Int64 intTraitID = Convert.ToInt64(chk.Attributes["TraitID"]);
SearchResult(intAspectID, intTraitID);
}
}
else
{
Int64 intAspectID = Convert.ToInt64(chk.Attributes["AspectID"]);
Int64 intTraitID = Convert.ToInt64(chk.Attributes["TraitID"]);
SearchResult(intAspectID, intTraitID);
}
}
else if (ctrl.GetType() == typeof(RadioButton))
{
}
else if (ctrl.GetType() == typeof(Image))
{
}
if (ctrl.HasControls())
{
if (Isall == false)
{
ProcessControls(ctrl, false);
}
else
{
ProcessControls(ctrl, true);
}
}
}
}