[英]accessing content page controls
我正在使用以下代碼從母版頁訪問內容頁內的控件
Button btn = (Button)ContentPlaceHolder2.FindControl("btnProceed");
btn.Text="test";
並且它確實在內容頁面中找到了控件並沒有異常地運行。但是按鈕文本沒有更改。在內容頁面中btnProceed Text字段設置為“ Proceed”。當我單擊圖像上的imageButton時,我需要的是母版頁內容頁btnProceed按鈕文本應更改為“ test”(當前未發生)。此問題的原因是什么?
你可以這樣嘗試...
Button btn= Master.FindControl("ContentPlaceHolder2").FindControl("btnProceed") as Button;
btn.Text ="test";
內容頁面上的按鈕是通過標記還是在運行時創建的? 如果在標記中,則以下代碼可以正常工作。
其母版頁上的圖像按鈕單擊處理程序
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Button btn = ContentPlaceHolder1.FindControl("Button1") as Button;
btn.Text = "Proceed";
}
如果我們在內容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.