Does a MasterPage know what page is being displayed?

前端 未结 12 1441
無奈伤痛
無奈伤痛 2021-01-02 11:53

When I navigate on a website utilizing MasterPages, does the application know what page I am on? If so, does it store it in an object I can access?

The reason I am

相关标签:
12条回答
  • 2021-01-02 11:58

    Yes, Use the below code in your master file. It will give you the content page name.

    Page.ToString().Replace("ASP.","").Replace("_",".")
    
    0 讨论(0)
  • 2021-01-02 12:02

    try

    this.Page.Master
    

    It will get you the master page of the current page.

    0 讨论(0)
  • 2021-01-02 12:03

    There's also the Request.RawURL

    0 讨论(0)
  • 2021-01-02 12:04

    You'd probably just use one of the Request path from within the master page to set the current. I'd probably also have a property on the master page to override it, so that pages without links or something could set it to something reasonable.

    0 讨论(0)
  • 2021-01-02 12:04

    The navigation control, not the master page, should be in charge of what page is currently highlighted.

    Either the page that is loaded should notify the navigation item who it is, or the nav control itself should keep track of it.

    The point is that master pages are supposed to simply be a holder that content is displayed in. They aren't supposed to control anything.

    0 讨论(0)
  • 2021-01-02 12:10

    Alternatively you can search for page title if you have set an specific title to the child page instead of masterpage try:

    this.Page.Title
    

    Hope it helps.

    0 讨论(0)
提交回复
热议问题