Dynamically Include (@reference) another Control or aspx file

A

Aamir Mahmood

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
 
H

Hermit Dave

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
 
M

Micael Baerens

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.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top