Loading controls dynamically in ASP.Net

S

supvine

Hello,

I am developing a page that has several custom web user controls that
need to be loaded dynamically. Some of the controls are loaded based
on the action (button-click) of a different control in the parent page.
Currently what I have to do to make this work is set a session
variable to load/unload a particular control and do a Server.Transfer
to the page itself from the Button_Click event. Is this a good way of
loading controls dynamically or is there a better way to do this? I am
using ASP.Net 1.1. Thanks.

Regards
 
S

supvine

Let's say that I have a page called Test.aspx which contains a button
called Button1 that has a corresponding Button1_Click event handler.
Let's also say that I have a control called TestControl.ascx which
contains another button called Button2. TestControl is added
dynamically due to Button1 click. When Button1 is clicked the page
execution happens as follows:

- Page_Load
- Button1_Click

If I have code inside Button1_Click to dynamically add the TestControl,
the next time the page is reloaded due to some other actions, say as a
result of Button2_Click in TestControl, the TestControl itself is not
loaded anymore. So I needed to have the logic in the Page_Load event
to check for a session variable to check if the TestControl should be
loaded or not. That way the TestControl is loaded as long as the
session variable is "true". On Button1_Click I set session variable to
"true" and do a Server.Transfer to itself. The Page_Load event looks
for that session variable and if it is set to true it loads the user
control dynamically.

Is there a better way of doing this? Thank you very much.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top