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 8737453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:31:35+00:00 2026-06-13T10:31:35+00:00

I’ve got a custom UserControl I’m working with which hosts dynamically created controls and

  • 0

I’ve got a custom UserControl I’m working with which hosts dynamically created controls and I’m running into an odd situation where I’m seemingly losing ViewState information. In my overridden SaveViewState method on the base.SaveViewState() call, I would expect it to return me back an object containing everything that was in ViewState, but it is instead returning null.

protected override object SaveViewState()
{

    object[] tempState = new object[2];
    tempState[0] = base.SaveViewState(); //***suspected issue here, tempState[0] == null -- why?
    //? this.ViewState["CompanyID"] returns me the guid I'm expecting
    //... code instantiating and populating lstDataControlInfos
    tempState[1] = lstDataControlInfos;
    return tempState;
}

I put a breakpoint in that method, and I can use the immediate window to query ViewState[“CompanyID”] and verify that there is indeed a CompanyID stored in ViewState. Maybe I’m misunderstanding something about ViewState, but shouldn’t that call be returning what is already in ViewState (including my CompanyID)? The issue becomes a problem on postback in the overridden LoadViewState method, as I no longer have any way to get CompanyID out of ViewState; it comes back null.

protected override void LoadViewState(object savedState)
{
    object[] tempState = (object[])savedState;
    //tempState[0] == null, as it was stored in the previous SaveViewState call
    //any reference to ViewState["CompanyID"] comes back null
    base.LoadViewState(tempState[0]);
}

I mentioned I’ve got dynamic controls I’m serializing to and deserializing from ViewState inside this control, and those all seem to be working properly. What would cause base.SaveViewState() to return null when I know for a fact and can verify (via immediate window) there is data in ViewState during the SaveViewState call?

  • 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. Editorial Team
    Editorial Team
    2026-06-13T10:31:36+00:00Added an answer on June 13, 2026 at 10:31 am

    When you save values to ViewState, the value is marked as dirty if ViewState is being tracked.

    Tracking starts in TrackViewState, which is after Initialize and before Load.

    Tracking ends in SaveViewState, which is after PreRender.

    If ViewState isn’t being tracked when a value is set in ViewState, it won’t be persisted when you call SaveViewState. This is a good thing: it means you can use ViewState during the Init phase without bloating the serialized ViewState.

    When you dynamically add controls to the tree, you should note that:

    • Values set before you add the control to the control tree will not be persisted, even if you add the control while ViewState is being tracked.

    • Values set after you add the control to the control tree will be persisted, if you are in a phase where ViewState is being tracked.

    At what point in the page lifecycle are you setting ViewState[“CompanyID”], and are you doing so before or after you add your control to the control tree?

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.