简体   繁体   中英

ASP Master and Content Page

I am using Master and Content Pages, now I have a situation that I dont want to use the css of Master page on Content Page. There are alots of classes and css files so overriding them is not possible I just have option to not include them in content page.

So what are the possible scenarios?

Having in mind that every equivalent method between the MasterPage and the ContentPage is being executed always later by the MasterPage (see here ), we have to introduce the CSS change inside the MasterPage .

That being said, you can detect the name of the ContentPage actually being displayed inside the Masterpage using Page.AppRelativeVirtualPath.ToString() in your ContentPlaceHolder .

Then, you can modify the css inside the masterpage saving it in an asp:Literal that includes the HTML link tag.

For example:

MasterPage.aspx

 <head> <asp:Literal runat="server" ID="cssStyleSheet"> </head> <body> <asp:ContentPlaceHolder ID="contentPageHolder" runat="server"> </body> 

MasterPage.aspx.cs

public void ModifyCSS(){
string contentPageName = contentPageHolder.Page.AppRelativeVirtualPath.ToString();
int pos = contentPageName.LastIndexOf("/") + 1;
contentPageName = contentPageName.SubString(pos, contentPageName.Length -pos);

switch(contentPageName)
{
  case "Login.aspx": 
  cssStyleSheet.Text = @"<link rel='stylesheet' type='text/css' href='Styles/Login.css' />";

    break;

  case "Logout.aspx": 
  cssStyleSheet.Text = @"<link rel='stylesheet' type='text/css' href='Styles/Logout.css' />"; 
    break;       
}}

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