简体   繁体   English

访问内容页面控件

[英]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? 并且它确实在内容页面中找到了控件并没有异常地运行。但是按钮文本没有更改。在内容页面中btnProceed Text字段设置为“ Proceed”。当我单击图像上的imageButton时,我需要的是母版页内容页btnProceed按钮文本应更改为“ test”(当前未发生)。此问题的原因是什么?

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: 如果我们在内容page.aspx中有以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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