简体   繁体   中英

accessing content page controls

i'm using following code to access controls inside content page from master page

 Button btn = (Button)ContentPlaceHolder2.FindControl("btnProceed");
            btn.Text="test";

and it does finds the control inside content page and runs with out exception.but the button text doesn't change.in the content page btnProceed Text field is set to "Proceed".what i need is when i click on a imageButton on the master page content page btnProceed button text should be changed to "test" which is currently not happening.what's the reason for this issue?

you could try like this...

 Button btn= Master.FindControl("ContentPlaceHolder2").FindControl("btnProceed") as Button;
 btn.Text ="test"; 

the button on content page is created by markup or at run time? if its in markup, the following code is working fine..

Its the image button click handler on Master page

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Button btn = ContentPlaceHolder1.FindControl("Button1") as Button;

        btn.Text = "Proceed";
    }

if we have in content page.aspx something like:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Button ID="Button1" runat="server" Text="Button" />
</asp:Content>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM