Click here to Skip to main content
15,921,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" EnableEventValidation ="false" CodeFile="ViewState1.aspx.cs" Inherits="ViewState1" %>

The value of textbox is still retained eventhough the page is posted to server using button control.
Posted
Updated 5-Sep-11 21:09pm
v2

Well, this very common and a very valid question.

I published one article, Beginner's Guide To View State [^] few years back, and in the discussion forum I have asked the same question. A silly question about viewstate.!!!!! Pin[^] You can check out my answer there.
Here is the details.
For the answer, first of all you need to know what actually happened during ASP.NET Page life cycle and ViewState.
In the ASP.Net page life cycle, two events related with View State.
1. Load View State : Where view state data is loading for the control and which happened before Page_Load.

2. Save View State : Where control data store in a hidden field before the Page_Render.

Now, If you disable the ViewState for the control it should store the view state data but, you are saying in Textbox, after you disabled the view state , control holds the data after postback,
Here is the Trick,
There is another event fired during Page Life Cycle, which is, Load PostBack Data Smile | :)
ASP.NET controls which implement IPostBackEventHandler will load its value from the appropriate postback data.
This value is not read from view state but from Postback From and this is true for those control which implements the IPostBackEventHandler
and TextBox is one such control Wink | ;)

One of my friend Brij, has a nice article on this Why textbox persists data during postback even if View State set to off[^]

Hope this clears your doubts and This will helps you.
 
Share this answer
 
v3
The answer is Controls which implements IPostBackEventHandler like Textbox, Checkbox, etc. will retain the state even after disabling the viewstate. The reason is during the LoadPostbackData stage, these controls will get state information from Posted back form.

But controls like label which do not implement IPostBackEventHandler will not get any state information from posted back data and hence depend entirely on viewstate to maintain the state.

Read this article you will get some idea

Why textbox persists data during postback even if View State set to off[^]

ViewState and Postback[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900