>
>They are loaded dynamically because they are not always needed. When specific data is chosen the controls are loaded via a control event. Then later when data needs to be saved, I have to get the values that were entered in the control. Sounds like I need to keep track somehow of what controls were loaded on every postback just to see if I need to reload them. Funny thing is I can't just see what controls are in the placeholder to be able to load them so I can query then later. What might be the most efficient way to keep track of what controls I add to a placeholder so I can reload them again?
Yeah, the whole stateless thing can be a bi***. ASP.NET hides that pretty well and it's easy to forget. Efficiency is debatable - it depends, like most things. You can add something into the session to track this, or create a viewstate variable to track it for you, or just use a hidden form field. Viewstate and/or session access stuff tends to look the same, the only difference is where the data is stored (in the page w/the client or on the server). If it's small enough, I usually use viewstate so I don't have to worry about that stuff sticking around in the session if the user happens to navigate away from the page before I get a chance to clean it out (even though it will go away once the session expires).
public string LoadedControlsName
{
get
{
object loaded = ViewState["LoadedControlsName"];
if (loaded != null)
return (string)loaded;
else
return "";
}
set { ViewState["LoadedControlsName"] = value }
}
public string LoadedControlsName
{
get
{
object loaded = Session["LoadedControlsName"];
if (loaded != null)
return (string)loaded;
else
return "";
}
set { Session["LoadedControlsName"] = value }
}
I happened to use a string, but it actually supports other serializable types as well.