Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
4.33/5 (2 votes)
See more: (untagged)
Hi,

There are two textboxes and one button control in a Web page. We change the setting as ViewstateEnabled=False to both the textboxes. In button click event we have written the code to display TextBox1 value in TextBox2.

The value is displaying in TextBox2 as well as it didn't remove from TextBox1 also even if both the textboxes ViewstateEnabled=False. What is the reason? Please answer.

Thanks in advance
Posted

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 :)
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

Hope this clears your doubts and This will helps you.

 
Share this answer
 
Please buy a basic book on ASP.NET and read it before asking all these questions.

 
Share this answer
 


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