LoadControl and PostBack

  • Thread starter Thread starter Craig Buchanan
  • Start date Start date
C

Craig Buchanan

I am trying to build a tabbed-style interface to capture information about a
person. I have one control that captures info about the person and a second
webuser control that captures information about the departments to which the
person is assigned. When a user clicks a tab, the appropriate WUC is
displayed.

Currently, I'm loading the appropriate control when Not IsPostBack. This
makes sense when a querystring is used to access the aspx page or to change
tabs.

Unfortunately, when one of the WUC posts back, the WUC is not loaded.
Obviously, I can't update any information in the WUC as it isn't there.

Does a control need to be loaded during postbacks as well? I suppose I
could always load both controls and hide the inactive one, but this seems
like an unnecessary waste of resources. Is there a better way?

Thanks,

Craig Buchanan
 
Hi Craig,

ASP.Net is stateless, which means that each Request occurs "in a vacuum" so
to speak. Once an ASPX page is processed, it is unloaded from memory.
Therefore, dynamically-added Controls must be dynamically added with each
PostBack.

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