2 Questions (Viewstate and ChildControlsCreated=false)

S

Steve Drake

All,

I have 2 Questions, I want to save some custom information to the viewstate,
I cannot do this via the usual property get and set I override the
LoadViewState and SaveViewState, is this a good idea?

code :

protected override void LoadViewState(object savedState)
{
base.LoadViewState (savedState);

if (ViewState["CurrentSearch"] != null)
{
currentSearch = (AdvancedSearchItemCollection)
ViewState["CurrentSearch"] ;
}
else
{
currentSearch = new AdvancedSearchItemCollection();
}
}
protected override object SaveViewState()
{
ViewState["CurrentSearch"] = currentSearch;
return base.SaveViewState ();
}

It does work, but I was unsure if this was a bad way todo this.

Also... If a server event needs to change what controls are created, is it
good pratise to set ChildControlsCreated to false? I've used this mehod
loads as the CreateChildControls gets run before the events, setting
ChildControlsCreated to false cause the CreateChildControls to get re-run,
again is this a good idea, if not what alternitives do I have.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top