Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Access to controls in placeholder
Message
 
To
11/09/2009 18:36:52
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
ASP.NET
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01423345
Message ID:
01424111
Views:
33
>
>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).
// What code looks like for viewstate
public string LoadedControlsName
{
   get
   {
      object loaded = ViewState["LoadedControlsName"];
      if (loaded != null)
         return (string)loaded;
      else
         return "";
   }
   set { ViewState["LoadedControlsName"] = value }
}

// What code looks like for Session
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.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform