To load a user control at runtime.

Posted by Santhi under ASP.NET category on | Points: 40 | Views : 1438
I tried the following scenario:

There is a dropdownlist control.
Based on the selection of dropdownlist item, the user control should be loaded to the page dynamically.
There are two user controls. Here you no need to give the reference of the user control in the aspx page.
You are going to load the user control at the runtime.

Control c= null;

   if (ddldropdownlist.StrSelectedValue == "Item1")
c= (Control)Page.LoadControl("DynamicControl.ascx");
else if (ddldropdownlist.StrSelectedValue == "Item2")
c = (Control)Page.LoadControl("DynamicControl2.ascx");
if( c != null)

Thanks & Regards,
V. Santhi

Comments or Responses

Login to post response