繁体   English   中英

在C#中使用母版页和Web表单

[英]Using master page and web forms in C#

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

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

</asp:ContentPlaceHolder>

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

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

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

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

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

我不知道您是否有权访问正在加载的页面,但是可以在母版页面上创建一个公共属性,例如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.<%
}

暂无
暂无

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

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