By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

ViewState

P: 14
Can Anyone help me regarding Viewstates
I have checked the properties as autopost back=false,enable viewstate=false
for the textbox properties.but still the Viewstate doesnot work,it still displays the last entered entries.
Please Reply me

Jyo
Apr 20 '07 #1
Share this Question
Share on Google+
3 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Can Anyone help me regarding Viewstates
I have checked the properties as autopost back=false,enable viewstate=false
for the textbox properties.but still the Viewstate doesnot work,it still displays the last entered entries.
Please Reply me

Jyo
Could it be that the browser has cached the entries that the user has made on the previous visit?

Could you explain a bit more about what is happening?

-Frinny
Apr 20 '07 #2

radcaesar
Expert 100+
P: 759
Hi Jyothi,
You had some false understanding on viewstate as of this TextBox is concerned.

Here is a note i got some long time back when i was googling.

TextBox does not use ViewState as its only mechanism to retain state over postback. When rendered in HTML browser, TextBox is normal INPUT element from browser standpoint. When form is posted, the value of that INPUT element is posted along with the form. This happens whether you have ViewState enabled or disabled. Note that TextBox implements IPostBackDataHandler interface, so it loads the related, posted value from form post collection in its implementation of IPostBackDataHandler.LoadPostData.

As you can see, value of Text property is actually stored to ViewState. So, how does TextBox use ViewState in this case? Well, in IPostBackDataHandler.LoadPostData TextBox uses ViewState as it compares the value of Text property to the value that is posted. As you probably guess, this is the case when TextBox's TextChanged event is raised if these values differ. If ViewState is disabled, Text property returns always String.Empty (it has not been assigned a value yet) and as a result posted value and Text property always differ and TextChanged event is raised every time.

After this, posted value is assigned to the Text property and rendered as the value of TextBox and things start over again. Note that Text property (ViewState collection actually) does keep its value during the same request even if ViewState is disabled. Disabling has impact on ViewState persistence not the functionality of ViewState collection. When ViewState is disabled, ViewState collection (System.Web.UI.StateBag) works similarly to the Context.Items collection. It is as it would be cleared for every request, but its values are valid during the same request.

Got it now ?
:)
Apr 20 '07 #3

P: 14
Hi..
Thanks for your reply...The indetailed version of urs helped me in understanding the concept!

Thanks again
bye


Hi Jyothi,
You had some false understanding on viewstate as of this TextBox is concerned.

Here is a note i got some long time back when i was googling.

TextBox does not use ViewState as its only mechanism to retain state over postback. When rendered in HTML browser, TextBox is normal INPUT element from browser standpoint. When form is posted, the value of that INPUT element is posted along with the form. This happens whether you have ViewState enabled or disabled. Note that TextBox implements IPostBackDataHandler interface, so it loads the related, posted value from form post collection in its implementation of IPostBackDataHandler.LoadPostData.

As you can see, value of Text property is actually stored to ViewState. So, how does TextBox use ViewState in this case? Well, in IPostBackDataHandler.LoadPostData TextBox uses ViewState as it compares the value of Text property to the value that is posted. As you probably guess, this is the case when TextBox's TextChanged event is raised if these values differ. If ViewState is disabled, Text property returns always String.Empty (it has not been assigned a value yet) and as a result posted value and Text property always differ and TextChanged event is raised every time.

After this, posted value is assigned to the Text property and rendered as the value of TextBox and things start over again. Note that Text property (ViewState collection actually) does keep its value during the same request even if ViewState is disabled. Disabling has impact on ViewState persistence not the functionality of ViewState collection. When ViewState is disabled, ViewState collection (System.Web.UI.StateBag) works similarly to the Context.Items collection. It is as it would be cleared for every request, but its values are valid during the same request.

Got it now ?
:)
Apr 24 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.