![]() |
|
|
|
#1 |
|
Hello everybody!
Imagine a form with several TextBox WebControls and two buttons "New" which should clear the form and "Save". On reloading or leaving the page which holds the form the TextBoxes should be cleared so I've disabled the ViewStates of these TextBoxes by setting the EnableViewState property to false. The method which is bound to the OnClick event of the "New" button is empty. When clicked a PostBack occurs which, theoretically, should be sufficient to clear the TextBoxes because their state shouldn't be saved. Unfortunately after the PostBack the data is still there! I've had a look into the HTML source and found out that the value property of the TextBoxes is set, so there's still a ViewState?! Even a ViewState.Clear() and/or ClearChildViewState() within OnClick() doesn't work! Disabling the ViewState for the whole page is no solution because the page also contains a DataGrid and other controls which depend on the ViewState. Please help! -- Sincerely Sven Jacobs Sven Jacobs |
|
|
|
|
#2 |
|
Posts: n/a
|
ViewState is a different state persistance mechanism than the normal <form>
post data. ViewState is for data that is not part of the normal POST. The text in a Label is saved in ViewState because a <span> doesn't post when the form is submitted. The text in a TExtBox will be submitted, and thus disabling viewstate has no effect on that. -Brock DevelopMentor http://staff.develop.com/ballen > Hello everybody! > > Imagine a form with several TextBox WebControls and two buttons "New" > which should clear the form and "Save". On reloading or leaving the > page which holds the form the TextBoxes should be cleared so I've > disabled the ViewStates of these TextBoxes by setting the > EnableViewState property to false. > > The method which is bound to the OnClick event of the "New" button is > empty. When clicked a PostBack occurs which, theoretically, should be > sufficient to clear the TextBoxes because their state shouldn't be > saved. Unfortunately after the PostBack the data is still there! I've > had a look into the HTML source and found out that the value property > of the TextBoxes is set, so there's still a ViewState?! Even a > ViewState.Clear() and/or ClearChildViewState() within OnClick() > doesn't work! > > Disabling the ViewState for the whole page is no solution because the > page also contains a DataGrid and other controls which depend on the > ViewState. > > Please help! > |
|
|
|
#3 |
|
Posts: n/a
|
> ViewState is a different state persistance mechanism than the normal <form>
> post data. ViewState is for data that is not part of the normal POST. The > text in a Label is saved in ViewState because a <span> doesn't post when > the form is submitted. The text in a TExtBox will be submitted, and thus > disabling viewstate has no effect on that. So what you saying is that the state persistance of a form is a feature of HTTP / the browser? How to clear the form then, via JavaScript? Thanks! -- Sincerely Sven Jacobs |
|
|
|
#4 |
|
Posts: n/a
|
> So what you saying is that the state persistance of a form is a feature of
> HTTP / the browser? How to clear the form then, via JavaScript? Forget that! After reading this article http://aspalliance.com/articleViewer.aspx?aId=135 I think I now what the difference between ViewState and PostBack data is. So what I have to do is not to import the PostBack data on a special condition (=New button clicked). -- Sincerely Sven Jacobs |
|
|
|
#5 |
|
Posts: n/a
|
No, the form persistance is a feature of the ASP.NET runtime, in that it
matches the control id in the POST data and fills the associated value from that. See http://msdn.microsoft.com/library/de.../viewstate.asp To clear the form, loop through the controls on the form, and check if the control is a textbox, or certain type of control, then set the value to an empty string, or index to -1 if a droplist etc. It really depends on what type of control you are working with as there is no generic way of clearing a form (AFAIK). -- - Paul Glavich ASP.NET MVP ASPInsider (www.aspinsiders.com) "Sven Jacobs" <> wrote in message news:178f7ojd7o9bi.719p7zwjzasv$.... > > ViewState is a different state persistance mechanism than the normal <form> > > post data. ViewState is for data that is not part of the normal POST. The > > text in a Label is saved in ViewState because a <span> doesn't post when > > the form is submitted. The text in a TExtBox will be submitted, and thus > > disabling viewstate has no effect on that. > > So what you saying is that the state persistance of a form is a feature of > HTTP / the browser? How to clear the form then, via JavaScript? > > Thanks! > > -- > Sincerely > Sven Jacobs |
|