When to save a variable in viewstate?
<p>I have searched the web for the answer and saw that mostly variables are saved in viewstate on page.prerender event. Then the value of the variable is set back in page load event.</p>

<p>However, when I save a variable in viewstate on prerender or load events, how can viewstate store the value of the variable after it is changed dynamically on codebehind?</p>

<p>Let's say, after page is loaded, user clicked a button which changes the value of the variable in its onClick event. 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 the variable is saved in the viewstate only in prerender event. Because on postback the prerender event wont fire and the value cannot be saved.</p>

<p>Shouldn't I save the variable in the viewstate just before the postback event rises?</p>

<p>Am I wrong? If so, how can viewstate store the new value of the variable if the viewstate is saved in prerender event?</p>

<p>Thanks for the answer in advance..</p>
