Persisting child controls

  • Thread starter Alexandre Soares
  • Start date
A

Alexandre Soares

Hi,

I've made a collapsible panel custom control. It's pretty simple so far, it
extends the Panel class and renders a bar above itself (panel) to show/hide
the <div> of the panel on the client-side using DHTML. So far it works fine.

I want to be able to make it work server-side as well: only the topbar is
rendered if the panel is to be collapsed and the topbar AND the panel are
rendered if the panel is to be expanded. But when I do that (hide and show
the panel), the properties of the child controls are not persisted.

Any hint on how I might do this?

Thank you,
 
K

Kevin Spencer

Use ViewState.

In a custom Server Control, this is absurdly easy to do. You create a
Property, something like the following:

public String PersistedProperty
{
get
{
if (ViewState["PersistedProperty"] == null) return "Default Value";
return Convert.ToString(ViewState["PersistedProperty"]);
}
set
{
ViewState["PersistedProperty"] = value;
}
}

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top