When to save a variable in viewstate?

Posted by Umut on Stack Overflow See other posts from Stack Overflow or by Umut
Published on 2010-06-09T22:36:11Z Indexed on 2010/06/09 22:42 UTC
Read the original article Hit count: 178

Filed under:

Hi,

I have searched the web for the answer and saw that mostly variables are saved in viewstate on page.prerender event.

However, when I save a variable in viewstate on prerender or load events, how can it store the changed value of the variable?

Let's say, after page load, user clicked a button and the value of the variable was changed in onClick event of the button. Then the postback event raised since the button was clicked. According to me, the new value should have been lost and cannot be saved in the viewstate if I save the variable in the viewstate only in prerender event.

Shouldn't I save the variable in the viewstate just before the postback event rises?

Am I wrong? If so, how can viewstate store the new value of the variable?

Thanks for the answer in advance..

© Stack Overflow or respective owner

Related posts about ASP.NET