Link to home
Start Free TrialLog in
Avatar of omegalove
omegalove

asked on

Value is lost on checkbox on cross post back.

if (SourceWithPhotoCHK != null)
                {
                    if (SourceWithPhotoCHK.Checked)
                        hdwithphoto.Value = "Y";
                    else
                        hdwithphoto.Value = "N";

                }

  public CheckBox CHBWithPhoto
        {
            get
            {
                return (CheckBox)ctrlSearch.FindControl("withphoto");
            }
        }
     
Avatar of Kamal Khaleefa
Kamal Khaleefa
Flag of Kuwait image

1)are you using html control or asp.net control
<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
keep the condition in PostBack

check the below condition in PageLoad

if(!isPostBack)
{
//write the checkbox code here
}
Make sure the checkbox have it's enableviewstate property to true.
Avatar of omegalove
omegalove

ASKER

<asp:CheckBox ID="wphoto" runat="server" Checked="True" OnCheckedChanged="wphoto_CheckedChanged" />
If you try :

<asp:CheckBox ID="wphoto" runat="server" Checked="True" OnCheckedChanged="wphoto_CheckedChanged" EnableViewState="True" />
I tried this and did not work.
ASKER CERTIFIED SOLUTION
Avatar of BurnieP
BurnieP
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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