Friday, April 18, 2008

PlaceHolder control in ASP .NET

PlaceHolder control acts as a container to store other web controls to a web page dynamically. It does not produce any output; its main function is used as a container for other controls. You can use the Controls.Controls collection to add, insert or remove controls from a PlaceHolder control.

Here is an example of how to add a web control to PlaceHolder control.

HTML
<form id="Form1" method="post" runat="server">
<asp:placeholder id="placeHolder" runat="server"> </asp:placeholder>
</form>


CODE BEHIND
Dim newLbl As New Label
newLbl.ID = "Label1"
newLbl.Text = "This is a label control. "
placeHolder.Controls.Add(newLbl)

Dim newBtn As New Button
newBtn.ID = "Button1"
newBtn.Text = "This is a button control. "
placeHolder.Controls.Add(newBtn)

' To remove the controls
placeHolder.Controls.Remove("Label1")
placeHolder.Controls.Remove("Button1")


Cheers!

0 comments:

 

Get paid for your opinions! Click on the banner above to join Planet Pulse. Its totally free to sign up, and you can earn UNLIMITED. Find out more by visiting PLANET PULSE.
July Code Blog Copyright © 2010 Blogger Template Designed by Bie Blogger Template