At run time add Web Server Controls to a PlaceHolder control in ASP.NET using VB.NET
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 given below.
-
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