omegalove
asked on
Value is lost on checkbox on cross post back.
if (SourceWithPhotoCHK != null)
{
if (SourceWithPhotoCHK.Checke d)
hdwithphoto.Value = "Y";
else
hdwithphoto.Value = "N";
}
public CheckBox CHBWithPhoto
{
get
{
return (CheckBox)ctrlSearch.FindC ontrol("wi thphoto");
}
}
{
if (SourceWithPhotoCHK.Checke
hdwithphoto.Value = "Y";
else
hdwithphoto.Value = "N";
}
public CheckBox CHBWithPhoto
{
get
{
return (CheckBox)ctrlSearch.FindC
}
}
keep the condition in PostBack
check the below condition in PageLoad
if(!isPostBack)
{
//write the checkbox code here
}
check the below condition in PageLoad
if(!isPostBack)
{
//write the checkbox code here
}
Make sure the checkbox have it's enableviewstate property to true.
ASKER
<asp:CheckBox ID="wphoto" runat="server" Checked="True" OnCheckedChanged="wphoto_C heckedChan ged" />
If you try :
<asp:CheckBox ID="wphoto" runat="server" Checked="True" OnCheckedChanged="wphoto_C heckedChan ged" EnableViewState="True" />
<asp:CheckBox ID="wphoto" runat="server" Checked="True" OnCheckedChanged="wphoto_C
ASKER
I tried this and did not work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
you are right. It should error out instead of being null
how can one check these mistakes. This is like old school where u have to pay attention to syntax
how can one check these mistakes. This is like old school where u have to pay attention to syntax
<ASp:CheckBox ...
also make sure at page load to add
if not page.isPostBack
also
make sure that you are not reSetting the checkbox
otherwise try to enable the viewstate of that control