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

  • Home
  • SEARCH
  • 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 850479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:16:18+00:00 2026-05-15T07:16:18+00:00

I stored a object in viewstate on Page. Now when i access the same

  • 0

I stored a object in viewstate on Page. Now when i access the same viewsate object on usercontrol,it shows as null. I even tried creating the same viewstate with same name in usercontrol and page.Both holds different value.

I understand that viewstate is a protected property. How does this thing implement in above scenerio or is there any other reason for this behaviour.

Edit:

Usercontrol is there in the page markup. I am not loading it dynamically.

I have a page EditFacilityworkType.aspx. On page I have a usercontrol FacilityWorkTypeDetails.aspx(FacilityWorkTypeDetails1). Inside this usercontrol i have a user control Workflow.aspx(Workflow1)

Page_Load() of Page
I am retrieving workflowdetails on page_load() of page.

 FacilityWorktype facilityWorkType = facilityDetails.GetFacilityWorktypeDetail(SessionHelper.FacilityWorkTypeID);
 ViewState["WorkFlow"] = facilityWorkType.FacilityWorkTypeWorkFlow

Inside usercontrol FacilityWorkTypeDetails.aspx. I have a property

 public FacilityWorktype FacilityWorkTypeDetails
{
    get
    {
        #region Fill FacilityWorktype
        return GetEntityFromControl();
        #endregion
    }
    set
    {
        PopulateControls(value);
    }
}

Now i set this property in page load of page

FacilityWorkTypeDetails1.FacilityWorkTypeDetails = facilityWorkType;

Inside Workflow.aspx, I have a property

/// <summary>
/// Property to fill entity object from controls on this page
/// </summary>
public WorkFlow WorkFlowDetails
{
    get
    {
        return GetEntityFromControls();
    }
    set
    {            
        BindTranscriptionMethodDDL(ddlTranscMethod);
        PopulateControls(value);
    }
}

Now PopulateControls() of FacilityWorkTypeDetails1, i am setting property of workflow1

private void PopulateControls(FacilityWorktype value)
{

    Workflow1.WorkFlowDetails = value.FacilityWorkTypeWorkFlow;
}

Now when i am retrieving values from

 private WorkFlow GetEntityFromControls()
 {
     WorkFlow workFlow = (ViewState["WorkFlow"] as WorkFlow) ?? new WorkFlow();  
     //workFlow  is null

 }

So now inside this function workFlow is null. I want to ask,why is it null when i have set viewstate in page.

  • 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-05-15T07:16:18+00:00Added an answer on May 15, 2026 at 7:16 am

    Scherand is very correct here. I’d like to add to what he has brought to the table.

    Every control that derives from System.Web.UI.Control has the ViewState property. Under-the-hood the property is a StateBag collection. Every instance of a Control has its own StateBag for ViewState, so as Scherand mentioned, ViewState is unique to the control. When the page gets rendered, the entire Control tree of the Page is iterated, all ViewState collections are merged into a tree-like structure and that final structure is serialized to a string and rendered to the page.

    Because the ViewState property is marked as protected, you can’t get to the Page’s ViewState from your User Control without the use of reflection.

    But, in all honesty, you should abandon the use of ViewState as a data storage medium. Here are some reasons why:

    1. ViewState gets rendered and output to the client browser. Maintaining data objects in the collection bloats your Page’s output.
    2. Unless you have encryption enabled on your ViewState, the encoded string that is rendered to the client browser can be decoded manually and simply anyone can access the content of your data objects. This is a rather significant security vulnerability.

    It really sounds like all you want to do is share data between your Page and User Controls. The best way to share data between controls is to make use of the “Items” collection (which is a property of the HttpContext class). The collection is a Hashtable and can be accessed from your Page and User Controls like so:

    Context.Items["Workflow"] = workflowInstance;
    

    The best part of using this technique is that it doesn’t incur any additional overhead or bloat the Page output. The Items collection exists in the context of a single HTTP request. This means that when your request is done and your Page’s output has been rendered to the client browser, the Items collection is cleared from server memory. It’s the ideal medium for temporary data storage within ASP.NET.

    Now, if you want your data objects to remain accessible for more than just the current request, you’d be better off storing the objects in Session.

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

Sidebar

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.