Loading controls dynamically in ASP.Net

Discussion in 'ASP .Net' started by supvine@gmail.com, Mar 22, 2006.

  1. Guest

    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
     
    , Mar 22, 2006
    #1
    1. Advertising

  2. Varangian Guest

    didn't understand why are you using a Session variable!?
     
    Varangian, Mar 22, 2006
    #2
    1. Advertising

  3. Varangian Guest

    didn't understand why are you using a Session variable!?
     
    Varangian, Mar 22, 2006
    #3
  4. Guest

    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.
     
    , Mar 22, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]
    Replies:
    0
    Views:
    604
    Ben Miller [msft]
    Aug 5, 2003
  2. sonic_soul
    Replies:
    0
    Views:
    522
    sonic_soul
    Aug 14, 2003
  3. =?Utf-8?B?V291dGVy?=

    Dynamically Loaded controls loading other controls

    =?Utf-8?B?V291dGVy?=, Feb 27, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    507
    =?Utf-8?B?V291dGVy?=
    Feb 27, 2006
  4. Bob Rock
    Replies:
    1
    Views:
    664
    Cowboy \(Gregory A. Beamer\)
    Sep 17, 2006
  5. Chris Lane
    Replies:
    1
    Views:
    125
    Hermit Dave
    Nov 25, 2003
Loading...

Share This Page