ARTICLE

How we can add Web Server Controls to a PlaceHolder control at run time

Posted by Manish Dwivedi Articles | ASP.NET using VB.NET April 16, 2007
This article explains you, the method for adding Web Server Controls to a PlaceHolder Control.
 
Reader Level:

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

share this article :
post comment
 

Don't add dynamic controls in Page_Load. They will not receive the ViewState back. Because this is given back between Page_Init and Page_Load. Put them in Page_Init.

Posted by Andrei Rinea Jun 03, 2007
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor