2
我有一個aspx頁面,它包含在主頁面中。我的aspx頁面具有用戶控件的用戶控件(ASCX)我打開了一個彈出窗口,獲取母版頁控件,我該如何做到這一點。訪問來自usercontrol的主控頁面控制的封裝在母版頁中的aspx
我有一個aspx頁面,它包含在主頁面中。我的aspx頁面具有用戶控件的用戶控件(ASCX)我打開了一個彈出窗口,獲取母版頁控件,我該如何做到這一點。訪問來自usercontrol的主控頁面控制的封裝在母版頁中的aspx
ASP.NET對於每個頁面'主'具有內部屬性。從usercontrol中,您可以將堆棧向後移動到Usercontrols父級> Page> Master。如果母版頁中的控件位於任何contentplace持有者之外,則可以使用FindControl方法獲取控件。如果它位於任何內容佔位符的內部,則必須遍歷內容佔位符,然後才能找到該控件。示例如下。
MASTER
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblVal" runat="server" Text="MasterLabel"></asp:Label>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
內容頁
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<test:uc ID="test" runat="server" />
</asp:Content>
用戶控件
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
用戶控件代碼隱藏
protected void Page_Load(object sender, EventArgs e)
{
MasterPage mstr = this.Parent.Page.Master as MasterPage;
Label1.Text = (mstr.FindControl("lblVal") as Label).Text;
}
在我的情況下,母版頁標籤是外部的內容頁面。
這很好,但我必須在用戶控制彈出訪問我已經嘗試了一些Java腳本,將無法獲得母版頁的控制(在ascx控制的彈出頁面(也是一個aspx頁面)) – pra