Tutorial :Object does not retrieves from viewstate


I am about to gone mad why? why? why?

protected void Page_Load(object sender, EventArgs e) { AttachedPartnersViewState vs = ViewState[SessionVariables.Company_AttachedPartnersViewState] as AttachedPartnersViewState;

protected override void OnUnload(EventArgs e)  {      ViewState[SessionVariables.Company_AttachedPartnersViewState] = _viewState;  

whatever I do. however I try to save this Viewstate, it seems to be ok on unload. then, as page is loading, it is NULL again, it DOESN'T retrieves despite page is on postback.

this is elementary action, but why it doesn't work?

BTW, control's EnableViewstate is true

Are there any explanations?


SaveViewState is before the Render Method. ViewState is encoded and written out to the page to be posted back in. If you add ViewState info after the Render, it is not written back out the the page. Hence it will not be read back in on the postback. Think of ViewState as a hidden input.


More on Page Lifecycle

More on ViewState

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »