Search
Author
ASP.NET Tutorials
Author
Sheo Narayan
Advertisements


Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook

Silverlight Tutorials | Report a Bug in the Tutorial
Share this to:

Bookmark It
asp:PlaceHolder control
PlaceHolder control is used as a container in which other controls can be added dynamically.
 
PlaceHolder control is used as a container in which other controls can be added dynamically. This control has no HTML output, it is used only to load a control at a specific place on the page (Whereas Panel control has <div> as HTML output.)
DEMO : PlaceHolder Show Source Code

This contorl and outer HTML Table also added from Server side
This text is from user control and this user control has been loaded at runtime.
This is the example of PlaceHolder contorl.
 
// PlaceHolder Control //////////////////////////////////
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

// Populates the PlaceHolder control //////////////////////////////////
private void PopulatePlaceHolder()
    {
        // Add ASP.NET Server Control
        TextBox txt1 = new TextBox();
        txt1.ID = "txt1";
        txt1.Width = 300;
        txt1.Text = "This control added from Server side.";
        PlaceHolder1.Controls.Add(txt1);

        // Add HTML controls
        string strHTML = "<hr /><table border='1'><tr><td>This contorl and outer HTML Table also added from Server side</td></tr><tr><td><input type='text' name='txtname' id='txtname' /></td></tr></table>";
        PlaceHolder1.Controls.Add(new LiteralControl(strHTML));
        
        // Add the usercontrol dynamically
        Control webUserControl = (Control)Page.LoadControl("~/tutorials/controls/controldata/WebUserControl.ascx");
        PlaceHolder1.Controls.Add(webUserControl);
    }