Value is lost on checkbox on cross post back.

omegalove
omegalove used Ask the Experts™
on
if (SourceWithPhotoCHK != null)
                {
                    if (SourceWithPhotoCHK.Checked)
                        hdwithphoto.Value = "Y";
                    else
                        hdwithphoto.Value = "N";

                }

  public CheckBox CHBWithPhoto
        {
            get
            {
                return (CheckBox)ctrlSearch.FindControl("withphoto");
            }
        }
     
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kamal KhaleefaInformation Security Specialist

Commented:
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

Commented:
keep the condition in PostBack

check the below condition in PageLoad

if(!isPostBack)
{
//write the checkbox code here
}

Commented:
Make sure the checkbox have it's enableviewstate property to true.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Author

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

Commented:
If you try :

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

Author

Commented:
I tried this and did not work.
Commented:
I don't know.. but you declare ID="wphoto"

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

But here you  are trying to find the ID "withphoto".  Is it normal?

  return (CheckBox)ctrlSearch.FindControl("withphoto");

Author

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial