开发者

How to identify content page loads in a master page dynamically?

开发者 https://www.devze.com 2023-01-01 20:43 出处:网络
I have a master page \'Master1\' and i have used a content place holder \'content1\' and loads pages \'Page1\' and \'page2\' in the \'content1\'. Is there any way to identify which page is loaded to t

I have a master page 'Master1' and i have used a content place holder 'content1' and loads pages 'Page1' and 'page2' in the 'content1'. Is there any way to identify which page is loaded to the content place holder whether it is 'Page1' or 'Page2' dynamica开发者_开发问答lly.


I think maybe you have misunderstood how master pages work?

In you master page you define the guts of your page that you want all pages to share, like headers and footers etc. The you define a content holder:

<asp:ContentPlaceHolder runat="Server" ID="MainContent">

</asp:ContentPlaceHolder>

The contents of Page1.aspx etc will be injected into that ContentPlaceHolder. Then in your aspx pages you simply define which master page it should use:

<%@ Page Language="C#" MasterPageFile="~/MyMasterPage.Master" ... />

and then define the content that should be injected in to the place holder in the master:

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
     put all your html in here
</asp:Content>

Note the id used for the ContentPlaceHolderID property, so that it gets injected into the right place - the master page could have several place holders. So both Page1.aspx and Page2.aspx can be loaded in to the place holder, all you have to do is navigate to whichever page you want to display. Nothing needs to be done on the master page.


Try this

ViewContext.RouteData.GetRequiredString("action")

0

精彩评论

暂无评论...
验证码 换一张
取 消