0

使用母版页时,无论如何我可以看到当前加载或加载到母版页中的 Web 表单,所以在此行之前:

<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

</asp:ContentPlaceHolder>

我想查看/获取将要加载到母版页中的 Web 表单,这可能吗?

4

2 回答 2

1

Page是的,您可以从母版页访问该属性。

要查看实际情况,请从 ASP.NET Web 应用程序(带有母版页)的默认 Visual Studio 模板中,将其转储到h1标题为的母版中:

My ASP.NET Application <%= Page.GetType().Name %>

它将在浏览器中显示为My ASP.NET Application default_aspx您所在的任何页面。

于 2013-04-02T15:17:51.197 回答
0

我不知道您是否有权访问正在加载的页面,但是您可以在名为 eg 的母版页上创建一个公共属性,currentPage并将其设置为Page_Load您想要的值。这样您就可以在 Site.Master 代码上查看它:

// on the Site.Master.cs
public string CurrentPage;


// on the page, inside the Page_Load event
((Site)this.Master).CurrentPage = 'My page';


// on the Site.Master
<%
if (CurrentPage == "My page")
{
    %>My page is loaded.<%
}
else
{
    %>Another page is loaded.<%
}
于 2013-04-02T15:12:02.293 回答