Solved

Save CheckBox state after postback

Posted on 2013-06-11
5
2,563 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
array not updating 8 42
Best book for Internet security 4 55
Java import explained 4 49
Ajax calendar distorted 4 21
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

751 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