ARTICLE

PlaceHolder Control in ASP.NET

Posted by Rohatash Kumar Articles | ASP.NET using VB.NET November 19, 2010
This article shows the PlaceHolder control in ASP.NET.
 
Reader Level:

This article shows the PlaceHolder control in ASP.NET.

PlaceHolder Control

The PlaceHolder control is used to reserve space for controls added by code. The PlaceHolder control does not produce any visible output (it only acts as a container for other controls on the Web page).

Property window:

pl.gif

Figure 1.

For example

Drag a PlaceHolder control on to the form. The following code will create two TextBoxes and a Button in code and will add them to the place holder at run time when a button is clicked.

Form looks like this.

pl1.gif

Figure 2.

Now double click on the button and add following code.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        TextBox1.Text = "Created TextBox11"

        TextBox2.Text = "Created TextBox12"

        Button1.Text = "Created Button"

        'setting text for the textboxes and button

        TextBox1.Columns = 15

        TextBox1.ReadOnly = True

        TextBox2.Columns = 20

        PlaceHolder1.Controls.Add(TextBox1)

        PlaceHolder1.Controls.Add(TextBox2)

        PlaceHolder1.Controls.Add(Button1)

        'PlaceHolder1.Controls.Add(CheckBox1)

        'adding the created textboxes and button to placeholder

    End Sub

End Class

 

Now save and run the application.


pl2.gif 

Figure 3.

 

Now click on the button.


pl3.gif 

Figure 4.

 

The above figure displays that placeholder contains textboxes and button control.                        

Login to add your contents and source code to this article
share this article :
post comment
 
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.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor