• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3011
  • Last Modified:

Save CheckBox state after postback

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
BigDeer
Asked:
BigDeer
  • 3
1 Solution
 
bepsoccer1Commented:
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
 
BigDeerAuthor Commented:
Does this work for the entire document? Anything else I need to do to get this to talk to my checkboxes?
0
 
BigDeerAuthor Commented:
I was able to resolve this issue with update panels. Thanks.
0
 
BigDeerAuthor Commented:
Resolved with update panels. Thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now