UserControl and Postback

  • Thread starter Thread starter supvine
  • Start date Start date
S

supvine

Hello,

I am developing a webpage (in .net 2003) that requires several
complicated user webcontrols to load different modules within the page.
Most of these webcontrols are loaded are runtime. Based on some action
(button-click) on these additional custom controls may be added or
removed from the page. The issue I am facing is that I am having to
load these dynamic controls everytime in Page_Load and as a result the
state of the control gets lost. Also, since Page_Load happens before
Button_Click event I am having to do Server.Transfer to reload some of
the data in the page.

Is there any better way to execute this in ASP.Net 1.1?

Thanks.
 
What type of data are you holding in these controls?

If you just need to save a few pieces of information, you could save
the information to Session["myVar"], and then retrieve the value on
postback.
 
Yes, that's what I am doing now but, I am having to reload the
webcontrols everytime the page is loaded and set each and every value
from the session. Plus since the Button_Click event occurs after
Page_Load it is creating more problems forcing me to add the user
controls once in the Button_Click event and then again in the Page_Load
event. I am just wondering if there is a better cleaner way to handle
such situations.

Thanks.
 
Are you familiar with the PreRender event? Try using the PreRender event
instead of page_load to access your control variables. You would still
dynamically assign the controls on the server in page_load. Assuming that
the Custom controls are maintaining its state correctly internally, due to
the Asp.net page event model, the user controls will not have loaded the
retained viewstate until the PreRender event fires (which is after the
page_load event). The effect of this would appear like the control has lost
its state when accessed in page_load. Accessing your control parameters in
the PreRender event may take care of your need to manually reload the
controls.
 

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

Back
Top