Tuesday, June 08, 2010

How to access controls with in different Content Place Holders

Sometimes it may necessary to access controls with in differnt Content Place Holders in the page. Solution is prefix Content Place Holder id with '$' control name.
Control control = this.FindControl("FooterPlaceHolder$txtSearch");

Example:

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
            <asp:SqlDataSource
                id="SqlDataSource1"
                runat="server"
                ConnectionString="<%$ ConnectionStrings:ActiveConnectionString%>"
                SelectCommand="SELECT * FROM dbo.Country"
                FilterExpression="Name='{0}'">
                <FilterParameters>
                    <asp:ControlParameter 
                      Name="Name"
                      ControlID="FooterContent$txtSearch" 
                      PropertyName="Text"/>
                </FilterParameters>
            </asp:SqlDataSource>
    
</asp:Content>
<asp:Content ID="FooterContent" runat="server" ContentPlaceHolderID="FooterContent">
    <asp:TextBox runat="server" ID="txtSearch" />
</asp:Content>

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...