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:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...