This is an ugly solution if you have many users, but you can embed the user controls themselves in the session. I do this with the footer control because I don't want to hit db every time the page changes to recreate the footer.
These solutions can actually perform tasks on the server if you have many users and they use this feature a lot. At least I think it will be ...
But you can just refill your placeholder, which has usercontrols in it on page_load. I can give an example soon.
An example of what I am doing:
if (Session["footer"] == null) { Session["footer"] = new Footer(LinksRules.BuildFooterLinks((int)WebSiteSections.Main));// where Footer is my control } footerPH.Controls.Add((Footer)Session["footer"]);
As a singleton view ...
So, as I see it, you can do it at all that will cause the postback
Session ["DynamicControls"] = PlaceHolder.Controls;
and in the method of loading the page, you can:
foreach(var control in (List<Controls>)Session["DynamicControls"]) { yourPlaceHolder.Controls.Add(control); }
and if the session object is null, just add one as if they were never there.
I believe this will hang with the data inside the controls as you want.
Ejc
source share