Solved

Save CheckBox state after postback

Posted on 2013-06-11
5
2,526 Views
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.
0
Comment
Question by:BigDeer
  • 3
5 Comments
 
LVL 4

Accepted Solution

by:
bepsoccer1 earned 500 total points
ID: 39239361
try this
protected override void LoadViewState(object savedState)
{
    base.LoadViewState(savedState);

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

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

    return base.SaveViewState();
}

Open in new window

0
 
LVL 3

Author Comment

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

Expert Comment

by:Monica P
ID: 39241390
0
 
LVL 3

Author Comment

by:BigDeer
ID: 39336506
I was able to resolve this issue with update panels. Thanks.
0
 
LVL 3

Author Closing Comment

by:BigDeer
ID: 39336509
Resolved with update panels. Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

685 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