ViewState Problem...PLEASE HELP!

  • Thread starter Thread starter Moshfegh Hamedani
  • Start date Start date
M

Moshfegh Hamedani

Hi there,

I have a simple web page containing a text box and a button. I set the
EnableViewState property of the text box to false. So, I expect that when I
type some text in the text box and hit the button, the text is not set to
the Text property of the text box after the page is posted back. But it
doesn't work at all !!! I even set the Page.EnableViewState to false but it
still loads view state data into text box after posting back.

So, what's the usage of View State ?!!! Any one here has any idea on this?

Please let me know,
Mosh
 
The text property is being set because it is not using viewstate. You are
setting the text, it is being posted to the server and the ASP.NET framework
is populating the appropriate control property. ViewState comes into play if
you want to do something once on a page_load, for example, and then allow
ViewState to maintain the state of the control. For instance, you could
populate a dropdownlist with items the first time the user hits the page and
then allow viewstate to maintain those items via its hidden form field
__VIEWSTATE.
 
Knowledge Base article 316813 explains the behavior you are noting.

http://support.microsoft.com/default.aspx?scid=kb;en-us;316813

Personally, I always disable ViewState on TextBoxes (or other controls
where it isn't necessary). HTH

(Incidentally, if you WANT the text box to be cleared on each
postback, you can easily accomplish this by doing it manually in the
Page.Load event.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top