Dynamically Include (@reference) another Control or aspx file

Discussion in 'ASP .Net' started by Aamir Mahmood, Nov 26, 2004.

  1. Hello,

    Can I include a control or another aspx file into a container aspx file on
    the basis of some parameters?\
    Like I want ControlA to be inserted in page index.aspx if the submit form
    has some specific value, and ControlB otherwise.

    -
    AM
    Aamir Mahmood, Nov 26, 2004
    #1
    1. Advertising

  2. Aamir Mahmood

    Hermit Dave Guest

    yeap you can certainly add controls at run time (even the ones written as
    user controls in .ascx)
    you can use place holder or any other container to insert the control.
    something like this.

    if( a == 1)
    {
    MyUserControl1 mUC1 = new MyUserControl1();
    myPlaceHolder1.Controls.Add(mUC1);
    }
    else
    {
    MyUserControl2 mUC2 = new MyUserControl2();
    myPlaceHolder1.Controls.Add(mUC2);
    }
    --

    Regards,

    Hermit Dave (D'way)
    http://hdave.blogspot.com

    "Aamir Mahmood" <> wrote in message
    news:...
    > Hello,
    >
    > Can I include a control or another aspx file into a container aspx file on
    > the basis of some parameters?\
    > Like I want ControlA to be inserted in page index.aspx if the submit form
    > has some specific value, and ControlB otherwise.
    >
    > -
    > AM
    >
    >
    >
    Hermit Dave, Nov 26, 2004
    #2
    1. Advertising

  3. Hello Aamir,

    > Hello,
    >
    > Can I include a control or another aspx file into a container aspx
    > file on
    > the basis of some parameters?\
    > Like I want ControlA to be inserted in page index.aspx if the submit
    > form
    > has some specific value, and ControlB otherwise.


    You can use the Page.LoadControl method to dynamically loading a control, and then place it somewhere in yout Page.Controls collection. But be aware that there can be issues with dynamically loading controls due to the way viewstate is handled.
    Micael Baerens, Nov 26, 2004
    #3
    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. vish
    Replies:
    2
    Views:
    1,705
    Steve C. Orr, MCSD
    Jul 16, 2003
  2. Mr. x
    Replies:
    1
    Views:
    1,942
    John Timney \(Microsoft MVP\)
    Nov 30, 2003
  3. Andreas Bogenberger
    Replies:
    3
    Views:
    859
    Andreas Bogenberger
    Feb 22, 2008
  4. Anthony Jones
    Replies:
    1
    Views:
    514
    Anthony Jones
    Jan 16, 2009
  5. Nathan Sokalski
    Replies:
    0
    Views:
    529
    Nathan Sokalski
    Jan 15, 2009
Loading...

Share This Page