Add a Web User Control Dynamically (At Runtime).

Posted by Chikul under ASP.NET category on | Views : 2900
We can add a Web User Control Dynamically (At Runtime) in 2 steps.

Step 1 : Add a "PlaceHolder" in your aspx page.

<form id="form1" runat="server">
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

Step 2 : Write the following code on page load (Code Behind).

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim UCDynamic As Control
'WebUserControl.ascx : User Control path
UCDynamic = LoadControl("WebUserControl.ascx")
End Sub


Comments or Responses

Login to post response