PlaceHolder Control in ASP.Net
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 is a container of other web server control
<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 run the project then all control will
not show on the page because here PlaceHolder Visibility is
false; and all control are inside PlaceHolder.
|