Add Web Server Controls to a PlaceHolder control at run time
This article explains you, the method for adding Web Server Controls to a PlaceHolder Control.
We can add the control's to a PlaceHolder by using the simple steps:
-
First we will create the instance of the controls, which we want to add in the PlaceHolder.
-
After that call the Add method of the PlaceHolder controls.
-
In the Add method we pass the instance of the control.
In the given Example, I am adding the three controls in a PlaceHolder.
Protected Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim Label1 As Label = New Label()
Label1.Text = "Enter Name"
PlaceHolder1.Controls.Add(Label1)
Dim TextBox1 As TextBox = New TextBox()
PlaceHolder1.Controls.Add(TextBox1)
Dim Button1 As Button = New Button()
Button1.Text = "Submit"
PlaceHolder1.Controls.Add(Button1)
End Sub