Source view of PLACEHOLDER.ASPX
DotNet Funda: Code Viewer
placeholder.aspx | placeholder.aspx.cs
Close Window  
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHeader" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderForTitleAndIntro" Runat="Server">
    <table width="100%" cellpadding="2" cellspacing="0">
        <tr valign="top" class="ArticleTitle">
            <td style="padding-left:10px;" valign="middle">
                asp:PlaceHolder control</td>
        </tr>
        <tr>
            <td class="ArticleContents">
                PlaceHolder control is used as a container in which other controls can be added dynamically.
            </td>
        </tr>
        <tr>
            <td colspan="2">&nbsp;</td>
        </tr>
    </table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderForContents" Runat="Server">
    <div class="ArticleContents">
    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 &lt;div&gt; as HTML output.)
        
        <!-- START - Demo Section -->
        <table class="DemoPlaceHolder" border="1" cellpadding="2" cellspacing="4">
            <tr>
                <td class="DemoTitle">
                    DEMO : PlaceHolder
                </td>
                <td align="right">
                    <a class="DemoShowSource" href="../../misc/codeviewer/default.aspx?pagename=~/tutorials/controls/placeholder.aspx" target="_blank">Show Source Code</a>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <pre>
// PlaceHolder Control //////////////////////////////////
&lt;asp:PlaceHolder ID="PlaceHolder1" runat="server"&gt;&lt;/asp:PlaceHolder&gt;

// 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 = "&lt;hr /&gt;&lt;table border='1'&gt;&lt;tr&gt;&lt;td&gt;This contorl and outer HTML Table also added from Server side&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;input type='text' name='txtname' id='txtname' /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;";
        PlaceHolder1.Controls.Add(new LiteralControl(strHTML));
        
        // Add the usercontrol dynamically
        Control webUserControl = (Control)Page.LoadControl("~/tutorials/controls/controldata/WebUserControl.ascx");
        PlaceHolder1.Controls.Add(webUserControl);
    }
                    </pre>
                </td>
            </tr>
        </table>
        <!-- END - Demo Section -->
        </div>
    <br />
    
    <script language="javascript" type="text/javascript">
        function GiveAlertToUser()
        {
            alert("Hi Dear, Client side method worked.");
        }
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PlaceHolderFooter" Runat="Server">
</asp:Content>

Go Top