Solved

Save CheckBox state after postback

Posted on 2013-06-11
5
2,386 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

19 Experts available now in Live!

Get 1:1 Help Now