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.
  • 1705

We can add the control's to a Placeholder by using the simple steps given below.

  1. First we will create the instance of the controls, which we want to add in the Placeholder.
  2. After that call the Add method of the Placeholder controls.
  3. 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

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.