Style sheet link in asp.net

Posted on 2013-09-30
Medium Priority
Last Modified: 2013-10-06
I have .aspx page(Masterpage Added).I want to apply the style sheet for that aspx page.Is it possible to apply style sheet with out header tag?
Question by:mannevenu26
  • 2
LVL 41

Expert Comment

ID: 39533651
Yes, you can insert css link from page_Load of that page or use Header PlaceHolders.
Check this: http://odetocode.com/articles/450.aspx (Headers,Scripts section)

Author Comment

ID: 39535478
Can u please give some example.how i can use Style sheet links in content page?
LVL 41

Expert Comment

ID: 39537511
1: Make sure the <head> in the master page has runat="server"
2: Include this code in the Page_Load of your content page:
HtmlLink cssLink = new HtmlLink();
cssLink.Href = "~/styles.css"; //this is the path to your stylesheet
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");

Open in new window


Accepted Solution

Johny Bravo earned 2000 total points
ID: 39537611
Sample Master page

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">

    <form runat="server">
    <div class="page">
        <div class="header">
            <div class="title">
                    My ASP.NET Application
        <div class="main">
            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
        <div class="clear">
    <div class="footer">

On your aspx page
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<link href="demos.css" rel="stylesheet" type="text/css" />

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        Welcome to ASP.NET!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
To export Lotus Notes to Outlook PST or Exchange and Domino Server files to Exchange Server or PST files with ease, go for Kernel for Lotus Notes to Outlook conversion tool. Through the video, you can watch the conversion process. A common user with…

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question