Save CheckBox state after postback

Posted on 2013-06-11
Last Modified: 2013-07-18
I think I'm making this much harder than it is but I'm having a time figuring it out.

I have a page that posts back with query strings in the URL and every time this happens my checkboxes clear to their default state. I've mucked around continuously using ViewState['variable'] = lbl.Text to collect the value of a label in order to populate the state of the checkboxes and have gottent nowhere. Every page i see online seems to be overcomplicating what I need it to do. Just need to save the state of a single checkbox or a label in order to pass a value to the checkbox.
Question by:BigDeer
  • 3

Accepted Solution

bepsoccer1 earned 500 total points
ID: 39239361
try this
protected override void LoadViewState(object savedState)

    if (ViewState["Checked"] != null)
        checked = (bool)ViewState["Checked"];

protected override object SaveViewState()
    ViewState["Checked"] = checked;

    return base.SaveViewState();

Open in new window


Author Comment

ID: 39239367
Does this work for the entire document? Anything else I need to do to get this to talk to my checkboxes?
LVL 10

Expert Comment

by:Monica P
ID: 39241390

Author Comment

ID: 39336506
I was able to resolve this issue with update panels. Thanks.

Author Closing Comment

ID: 39336509
Resolved with update panels. Thanks.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
iframe detection of parent window scale 20 59
IIS issues - Convert to Application - APS.NET v4.0 3 19
Need a starter for ETL protocol? 4 38
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now