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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:26:27+00:00 2026-05-11T03:26:27+00:00

Is there any guideline or rule for when the view state should be enabled

  • 0

Is there any guideline or rule for when the view state should be enabled on a server control? And when it should not?

I was looking at this SqlDatasource example and noticed that the view state for the label control is not enabled:

<asp:Label ID='ErrorMessageLabel' EnableViewState='false' runat='server' /> 

Why isn’t EnableViewState enabled on the label control? I know that enabling the view state carries some overhead so I would like to use it only when it is needed.

  • 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-11T03:26:28+00:00Added an answer on May 11, 2026 at 3:26 am

    Here’s a good rule of thumb: If you (1) change a property’s value in the code-behind, and (2) need to know what value you set in a later postback without recalculating the value, then you need to use ViewState.

    For example. In my page’s markup I might have a Label control specified like this:

    <asp:Label ID='TitleLabel' runat='server' Text='Update this Employee' /> 

    Then in the Page_Load event I have this code:

    If Not IsPostBack AndAlso myEmployeeObject.IsNew Then TitleLabel.Text = 'Create a new Employee' 

    By changing the value of the Text property, I’ve introduced a new element into ViewState. If I get the value of the Label’s Text property during any subsequent PostBack, the value will be ‘Create a new Employee’.

    Here’s what I do when I set out to minimize the amount of ViewState used by my page. I enable tracing on the page. The trace output is added to the bottom of your page when its rendered in the browser. The trace output identifies every single server control on your page and includes how much ViewState (measured in bytes, I believe) each control stores. I use this information to calculate when I want to trade the overhead of ViewState for the overhead of recalculating values.

    In my previous example, I would elect to recalculate the Label’s Text property on every PostBack and stop storing the Text property in ViewState. This is how my updated markup would look:

    <asp:Label ID='TitleLabel' runat='server' Text='Update this Employee' EnableViewState='false' /> 

    And my updated Page_Load event:

    If myEmployeeObject.IsNew Then TitleLabel.Text = 'Create a new Employee' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any pdf which tells about coding guidelines in objective C. For Example...
I'm using guidelines right now, but I do not think there is any way
Is there any guideline or standard best practice how to version a software you
Is there any guideline to make the decision where to host WF: in our
Is there any guideline for creating optimized graphics for an iOS 2d game. Actually
Is there/has somebody any comparison, personal experience, or guideline when to use the text
Are there any guidelines where should my app store resource files downloaded from internet?
Is there any design guideline on the number of Activities an application could have?
Are there any guidelines to writing Google App Engine Python code that would work
Is there any guidelines on how to differentiate between .nil? , .blank? and .empty?

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.