简体   繁体   中英

Master pages — Getting calling page name

Can someone tell me how to get the name of the child page being called in a Master page scenario. For example, if I have the following masterpage:

<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
    <asp:ContentPlaceHolder ID="cphMainContent" runat="server">
    </asp:ContentPlaceHolder>
</body>
</html>

And I create a page called Test.aspx which inherits this masterpage, how can I, from the masterpage, know that Test.aspx has been requested (since this masterpage can be inherited by more then 1 aspx page)?

这是您要问的问题类似的问题 ,但是我要注意已接受的答案,试图从母版页中找出子页可能不是一个好的设计思想。

I would notify in the other direction. Add properties to your master page then set them from the content pages.

In your master:

public partial class PortalMaster : System.Web.UI.MasterPage
{

    public string PageSection { get; set; }
}

In your .aspx add this directive:

<%@ MasterType VirtualPath="PortalMaster.master" %>

Then in your .aspx.cs set the property value like so:

Master.PageSection = "about";

Going with your comments, I see a couple of options:

1) In your login page, on a non-postback, check the Referrer - this will be the page that sent you to the login page ( Request.UrlReferrer ), store that in session for the postback of their login details, and then send the user back.

2) Use the standard features of ASP.NET to handle login/redirections (which basically use the same system as 1).

只需使用母版页的“页面”成员

从MasterPage的Page.AppRelativeVirtualPath代码中, Page.AppRelativeVirtualPath属性将告诉您路径。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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