Microsoft KB Archive/316813

= PRB: Server controls persist their state when EnableViewState is set to False =

Article ID: 316813

Article Last Modified on 2/23/2007

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0

-



This article was previously published under Q316813



SYMPTOMS
The following server controls persist their information across requests even when the control ViewState (the EnableViewState attribute) is set to False:
 * The TextBox control.
 * The CheckBox control.
 * The RadioButton control.



CAUSE
This behavior occurs because the ViewState of a control is only one of the methods that are used to persist a control's attributes across requests. In the server controls that are mentioned in the &quot;Symptoms&quot; section, attributes that are not normally posted to the server through the form-get or the form-post are handled by the ViewState. These values include attributes of the control, such as BackColor. Attributes that are normally posted to the server are handled by the IPostBackDataHandler interface. An example of such an attribute is the checked attribute of the CheckBox control.



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
 Create an .aspx page with a Web Forms CheckBox control(ID=CheckBox1) and a Button control.  Add the following Microsoft Visual C# code for the Page_Load event: private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) {       CheckBox1.BackColor = Color.FromName(&quot;Tomato&quot;); } }                    Verify that the EnableViewState property for the CheckBox control is set to True. Save and compile your project, and then browse to the .aspx page.

Even though the background color for the CheckBox control is set when you first request the .aspx page, it is maintained across requests when you submit the form with the button. Set the EnableViewState property of the Checkbox control to False. Save and compile your project, and then browse to the .aspx page with a new instance of the browser.</li> Click to select the check box for the checked attribute. When you resubmit the .aspx page with the button, the background color of the Checkbox control is lost. However, the checked state of the control is maintained.</li></ol>

Additional query words: view state

Keywords: kbprb kbservercontrols kbstate kbwebforms KB316813

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.