How to Load User Control Dynamically


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);

 

 

About author


User avatar

Waqas Anwar

Founder of EzzyLearning.com, Senior Consultant, Microsoft .NET and Web Technologies

Comments