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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:35:16+00:00 2026-06-08T17:35:16+00:00

I want to assign values to server control properties in my code behind to

  • 0

I want to assign values to server control properties in my code behind to “initialize” a form. I don’t need/want these values to be added to the viewstate. (I know I can disable viewstate for a specific control, but I need viewstate as some values may change and need to be persisted during postbacks.)

At the moment for me it seems its not possible to load these values in code without having them added to the viewstate.

As I understand the following happens:

Page: PreInit

I could add values to SOME controls (its working for example with a literal control to set the text value) here BUT since control’s init methods are executed later I cannot for example find a RegisterUser control and its child controls at this stage yet, they are still null. > so no solution in this specific case, there’s more cases

Control: Init

I cannot reach this point from within my page, this can only be used inside the user control code for example when you write your own usercontrol and want to initialize its values, I ofcourse dont want to create my own control for each control I need to initialize with executing some logic first.

Control: TrackViewState

Viewstate Tracking is enabled so from here on after anything I set will be marked as ‘dirty’ and therefore added to the viewstate.
Page:Init
Page:TrackViewState

So am I right in saying:

In code behind, without disabling a controls viewstate property..

  • You can initialize “1st level” child control properties from the page control in the PreIinit method without having the value being added to the viewstate.
  • You cannot initialize Child control properties from controls that are “1st level” child controls of the page without having the value added to the viewstate.
    ?

Then,

  • You can initialize control properties declaratively by using resources, but this does not circumvent the scenario where you need to execute logic
  • You can execute logic by using databinding syntax but you would have to manually call databind on the control having the same issues as above

Is there no way to iterate a set of controls/child controls and initiate values in code behind withouth having these values added to the viewstate?

  • 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-08T17:35:17+00:00Added an answer on June 8, 2026 at 5:35 pm

    With no reactions here and some further research, I am now at the point to conlude that you can indeed NOT iterate a set of controls/childcontrols and initiate values in code behind without having these values added to the viewstate, because of reasons mentioned in the question.

    There are some partial solutions however as made clear here: http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx

    One possibility is to hook into the init event of the control itself declaratively, you would have to do that for each control. In code behind, inside the event handler you can set the property and since viewstate is not tracking yet it will not be saved in viewstate.

    There are more options for different scenario’s for example initializing dynamically added child controls inside a custom control by overriding the CreateChildControls method. Definately worth reading the above mentioned ‘Truly Understanding Viewstate’ link.

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

Sidebar

Related Questions

If I want to declare a vector of unknown size, then assign values to
I want to assign a matrix N values long to N entries in a
Can I access server control values in aspx design page. For now being its
I want to assign a value from a select box to an input field
I want to assign the value in QString to a const std::string QString qfile(some
IDirect3DSurface9 *var = NULL; IDirect3DSurface9 *** ret; I want to assign the value dereferenced
I want to assign a NiceMock with the return value of a method. The
I want to assign the array item into variable directly using groovy like this:
I want to assign categories based upon the format of the book that will
I just want to assign a variable to a function so it can be

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.