Search

Sunday, February 2, 2014
0 comments

How to use PlaceHolder Control in ASP.NET

1:04 AMSunday, February 2, 2014
The PlaceHolder Control
The PlaceHolder control is used as a container to store server controls that are added to the Web page at runtime. The PlaceHolder control does not produce any visible output and is used only as a container for other controls on the Web page.

Example of PlaceHolder control

 
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox text = new TextBox();
        text.Text = "This is the runtime textbox";
        text.Style["width"] = "300px";
        PlaceHolder1.Controls.Add(text);       
           
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Click to add TextBox" OnClick="Button1_Click" />
        <br />
        <br />
        <br/>
        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
    </div>
    </form>
</body>
</html>
Output
Add Textbox on runtime
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top