1
Answer

Calling a user control dynamically.

Photo of kchoms

kchoms

18y
3.6k
1
Hello,
I need to know how to access the user controls dynamically.
There is a drop down list with the name of the forms. If the user selects a form and hits submit some user controls should be displayed based on the selected form.

There is a table which contains the Form Name. name of user control and the order in which they should appear. Based on this table can i call the user controls and place them in the screen. Please let know how this can be done?

Thanks
Sowmya

Answers (1)

0
Photo of Dipen Lama
NA 331 195.9k 18y
Use Place holder control to place the user control dynamically.
Here is some lines:

    string userControlName = "UserControl1.ascx"; 
 
    Control control1 ;
    control1 = LoadControl( userControlName );
    placeHolderControl1.Controls.Clear();
    placeHolderControl1.Controls.Add( control1 );