Apply CSS to Content Page in Asp.NET

Normally when we are using Master/Content style pages, we apply the css to Master page so every page child of the master page can use the style but I don’t want this,I want I wanna apply css to content page directly instead of master page. Where should I put

<link rel="stylesheet" href="css/lightbox.css" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" type="text/css" media="screen" />

that reference code ?

Thanks in advance by the way.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Normally I put a content placeholder in the head section of the master page. That way any content page can add extra css/js/etc references to the head of the page.

In your master page put the following

<head>
  ... title, meta tags, js and css links ...
  <asp:contentPlaceholder id="head" runat="server" />
</head>

Then in your pages you can include extra elements in the head using this
<asp:content contentplaceholderid="head" runat="server">
 <link rel="stylesheet" href="css/lightbox.css" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" type="text/css" media="screen" />
</asp:content>

Method 2

Put a content placeholder in the head portion of your master page. Not all content pages will need to place anything in it but this particular content page can place the CSS file you want to link.

Method 3

You can’t apply a style sheet to a content page only, it applies to the whole web page.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x