How to Load User Control Dynamically

Waqas Anwar
08 June 2009
5042 Views

If you have created a User Control (.ascx) and you want to add them on page dynamically on the page, you can use LoadControl method of Page class


To add User Control dynamically on the page:

headerControl = Page.LoadControl("HeaderControl.ascx");

Page.Form.Controls.Add(headerControl);

To add User Control dynamically exactly where you want on the page use PlaceHolder control
PlaceHolder1.Controls.Add(headerControl);