grady
grady

Reputation: 12755

LoadViewState and SaveViewstate?

I cretated my own server control (a dropdownlist) and thus my own LoadViewState and SaveViewState methods. When is the LoadViewState called? I added the control to my page and looked when the methods are called. Only the SaveViewState is called when the page is requested, LoadViewState is not. Do I have to call it manually?

Thanks :)

Upvotes: 4

Views: 9344

Answers (2)

mikemanne
mikemanne

Reputation: 3575

The diagram on this MSDN page of the ASP.NET page lifecycle is an excellent reference to have on-hand for these sorts of questions (it's printed out and taped on my cube wall right now).

As you'll see on the diagram, LoadViewState for a control is called after the page's Init, and before the page's PreLoad; it is called only on postback, not on initial page load.

A control's SaveViewState is called after the page's PreRenderComplete, but before the actual Render.

Upvotes: 4

Brian Mains
Brian Mains

Reputation: 50728

After Init, but before Load. LoadViewState does not run on the initial page load, but subsequent page loads. No need to when no state exists. No you do not need to call manually. You just need to worry about the data you want to save, and reloading that data during the loading phase.

Upvotes: 0

Related Questions