articles

Home / DeveloperSection / Articles / PlaceHolder Control in Asp.Net

PlaceHolder Control in Asp.Net

PlaceHolder Control in Asp.Net

Pushpendra Singh 18273 28-Oct-2010

The PlaceHolder Web server control does not have any visible output and is used as a place holder when we add controls at run time. The PlaceHolder control is used to reserve space for controls added by code.

<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

PlaceHolder Control in Asp.Net

PlaceHolder is a container of other web server control

PlaceHolder Control in Asp.Net

 

<asp:PlaceHolder ID="PlaceHolder1" runat="server">
Search this website:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 
<asp:Button ID="Button1" runat="server" Text="Start Searching" />
</asp:PlaceHolder>

The advantage of using PlaceHolder is that the textbox, button and other content contained within the PlaceHolder opening and closing HTML tags are kept as a single entity. For example, to hide the entire search form (i.e. text label, textbox, and button) only a single line of C# code is required:

protected void Page_Load(object sender, EventArgs e)
    {
        PlaceHolder1.Visible = false;
    }

Now when running the project then all control will not show on the page because here PlaceHolder Visibility is false, and all control are inside PlaceHolder. 

PlaceHolder Control in Asp.Net


Updated 26-Mar-2020

Leave Comment

Comments

Liked By