Showing posts with label User Control. Show all posts
Showing posts with label User Control. Show all posts

Add a Web User Control Dynamically (At Runtime).

We can add a Web User Control Dynamically (At Runtime) in 2 steps.

Step 1 : Add a "PlaceHolder" in your aspx page.
Step 2 : Write the following code on page load (Code Behind).

Code :
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