In this example i have told you how to load web user control dynamically in your ASP.NET web form. ASP.NET have .aspx file extension where as web user control have the .ascx file. In this example, i have assumed that you know, how to create a web user control.
Here’s is the solution
C#
protected void Page_Load(object sender, EventArgs e)
{
Control userControl = Page.LoadControl("WebUserControl.ascx");
Page.Form.Controls.Add(userControl);
}
VB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim userControl As Control =
Page.LoadControl("WebUserControl.ascx")
Page.Form.Controls.Add(userControl)
End Sub
Download
LoadControl.zip (1.93 kb)