Add a Web User Control Dynamically (At Runtime).

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

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


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


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")
PlaceHolder1.Controls.Add(UCDynamic)
End Sub


Regards,
Chikul

Comments or Responses

Login to post response