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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:43:53+00:00 2026-05-12T21:43:53+00:00

In some book I’ve seen that they save custom properties of user control like

  • 0

In some book I’ve seen that they save custom properties of user control like this:

 private int id = 0;
   public int ID
   {
      get { return id; }
      set { id = value; }
   }

   protected void Page_Init(object sender, EventArgs e)
   {
      this.Page.RegisterRequiresControlState(this);
   }

   protected override void LoadControlState(object savedState)
   {
      object[] ctlState = (object[])savedState;
      base.LoadControlState(ctlState[0]);
      this.ID = (int)ctlState[1];
   }

   protected override object SaveControlState()
   {
      object[] ctlState = new object[2];
      ctlState[0] = base.SaveControlState();
      ctlState[1] = this.ID;
      return ctlState;
   }

My question is why can I simply store it (in setter) in viewstate like: Vistate[“ID”]=id;
and then retrieve it form there?

  • 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-12T21:43:54+00:00Added an answer on May 12, 2026 at 9:43 pm

    There is a difference between ViewState (what you are talking about in your question) and ControlState (what is shown in the sample code):

    • ViewState can be turned off by the user of your UserControl, by setting EnableViewState="false". In that case, you wouldn’t be able to restore your property’s value during the next request/postback (because there is no ViewState).
    • ControlState cannot be turned off. This means, that whatever you store in ControlState will be available during the next postback and you should therefore use ControlState for data that you absolutely need to be able to retrieve during the next request/postback.

    See also these pages in MSDN: ASP.NET ViewState Overview and ControlState vs. ViewState

    Excerpt from the first page:

    In addition to view state, ASP.NET
    supports control state. The page uses
    control state to persist control
    information that must be retained
    between postbacks, even if view state
    is disabled for the page or for a
    control. Like view state, control
    state is stored in one or more hidden
    fields.

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

Sidebar

Related Questions

In the book Linux System Programming I have read some like this: fgetc returns
I am doing some exercises in my object-oriented javascript book, I notice that this:
I have seen this in some book/ tutorial. When you pass in the head
I have some pages that display book informations, and they use an external cover
I am reading some book and I have encountered a piece of code that
I have a class Book which has some annotations like @Override , @Before ,
Is there any book or links that I can read some tutorial about the
In some book, it is recommended that to_param is changed to class Story <
I study this code from some book: #include <pthread.h> #include <stdio.h> /* Parameters to
I grabbed this code form some book I've bumped on the InternetS... sm: new

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.