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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:47:56+00:00 2026-05-28T13:47:56+00:00

I have a question about viewstate and custom controls in asp.net. Say I have

  • 0

I have a question about viewstate and custom controls in asp.net.

Say I have a page and a simple composite control on it. I know that in the composite control I have to load all my children control on Page.OnInit so that their viewstate can be applied and be ready for OnLoad.

Now say I have a tree on the page and based on the selected node I would like to load a certain custom control. The treeview’s selectedNode is not available during OnInit, but is available on OnLoad and after. I also know that if I add a custom control on the OnLoad of a page that customs control’s cycle is still going to start with OnInit and then to OnLoad, etc etc.

So my question is, if the custom’s control’s OnInit is still being called even though I am loading this control in the parent’s OnLoad method, why doesn’t the viewstate get populated for the custom control?

Is it because the parent contains the the viewstate for the children and if i load children from parent’s OnLoad the viewstate is not available?

How do you usually go about loading custom controls if you have a situation I described above (with the treeview)?

  • 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-28T13:47:56+00:00Added an answer on May 28, 2026 at 1:47 pm

    ASP.NET does load viewstate for child controls even if they’re added to the page in OnLoad, as this example demonstrates:

    protected override void OnLoad(EventArgs e)
    {
        Literal literal = new Literal();
        this.placeHolder.Controls.Add(literal);
        if (!this.IsPostBack)
            literal.Text = "I'm still here after a postback.";
    }
    

    Note that, by default, ASP.NET loads viewstate based on the indexes of the child controls, so make sure the order of your controls is consistent from one postback to the next.

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

Sidebar

Related Questions

I am new to asp.net and have got some concerns about the bloated viewstate
A dumb question: Let's say I have an object that i store in viewstate.
I have question about this plugin system: .NET 4.0 ASP.NET MVC 3 plug-in architecture
My question is simple. About 2 years ago we began migrating to ASP.NET from
I have question about managing transaction in asp.net application. For example i have application
I have question about database optimizing, indexing. I have table that called projects and
I have an ASP.NET WebForms control (derived from Control, not WebControl, if it helps)
I have question about why 2 controls in separate repeaters cannot have the same
I have been writing a bunch of generic ASP.NET controls, and one thing I
This is about ASP.NET, ViewState, UserControls and losing the values of my properties. It

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.