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

We can add the control's to a PlaceHolder by using the simple steps:

  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.