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.
Steps to explain above behaviour
1) Create a Web Site project
2) Add a web page to project for example Default.aspx
3) Add below HTML code to Default.aspx page
<form id=”form1″ runat=”server”>
<div>
<label enableviewstate=”false” id=”lblTest” runat=”server”></label>
<textbox enableviewstate=”false” id=”txtTest” runat=”server”></textbox>
<button id=”Button1″ runat=”server” text=”Submit” type=”submit”></button></div>
</form>
4) Write below code in Page_Load event in Default.aspx.cs
(!IsPostBack)
if
{
lblTest.Text = “Test Label”;
txtTest.BackColor = Color.FromName(“Tomato”);
txtTest.Text = “Test TextBox”;
}
5) Save and compile your project, and then browse to the .aspx page.
6) Now click on Submit button and observe the changes.