Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 143001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:01:34+00:00 2026-05-11T08:01:34+00:00

I’m writing a custom control in ASP.Net 3.5 WebForms, using ASP.Net AJAX. I’m building

  • 0

I’m writing a custom control in ASP.Net 3.5 WebForms, using ASP.Net AJAX. I’m building a state toggle into the control (expanded and collapsed modes). I’ve been trying to keep the current state of the control in ViewState, changing it in a server-side event handler manually:

object oExpanded = ViewState[ 'Expandedness' ]; if(oExpanded == null) {     oExpanded = ListState.Collapsed; } ListState lsCurrentState = (ListState) oExpanded; if(lsCurrentState == ListState.Collapsed) {     //code snipped - move to expanded mode here     ViewState[ 'Expandedness' ] = ListState.Expanded; } else {     //code snipped - move to collapsed mode here     ViewState[ 'Expandedness' ] = ListState.Collapsed; } 

I don’t think it should matter, but the actual rendering happens in an updatepanel and the code above is in an event handler that’s triggered asynchronously. The problem I have is that on the next postback, ViewState['Expandedness'] returns null. I’ve tried to use Fritz Onion’s Viewstate Decoder tool to look at the actual contents of viewstate between postbacks, but it tells me the serialized data is invalid.

Have I taken a wrong approach here? What’s the right way to tackle this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:01:35+00:00Added an answer on May 11, 2026 at 8:01 am

    You’re right that it’s OK for it to be in an UpdatePanel – this shouldn’t make any difference.

    I suspect that the ViewState is disabled either for your control or for one of its parents: if it’s disabled for any parent (all the way up to the page), it’ll be disabled for your control.

    To get round this, you can use the page’s ViewState dictionary instead of the one on your control.

    I.e. instead of saying:

    this.ViewState[ 'Expandedness' ] = ListState.Expanded; 

    say:

    this.Page.ViewState[ 'Expandedness' ] = ListState.Expanded; 

    If it’s possible that there’s more than one instance of your control on the page, you’ll need to ensure the ViewState key is unique, perhaps like this:

    this.Page.ViewState[ this.ClientID + 'Expandedness' ] = ListState.Expanded; 

    As an alternative (that will work even if ViewState’s disabled for the page), you could consider storing the Expandedness in the ControlState. It’s a bit trickier, but google it and you’ll find a code sample pretty quickly. It’s recommended you store only an absolute minimum of information in the ControlState, but a single flag like this is fine (and actually what it’s designed for, really).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.