How to select stylesheet by url

Posted on 2013-01-02
Last Modified: 2013-01-07
I am using vs2010.

My default  page is referenced as follows during testing:


I have created  2 styesheets, css1 for product a,  css2 for products b

I want to reference css1 for product a and css2 for product b

The stylesheets are assigned in default.aspx

How can I select a stylesheet by url (example: http://localhost:xxxx/default.aspx?/products=a to use css1) for the body of default.aspx

Thanks in advance,
Question by:TechIsaac
  • 2
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 500 total points
ID: 38739071
you can dynamiccaly assign the style sheet

protected System.Web.UI.WebControls.Literal StyleSheet;

   private void Page_Load(object sender, System.EventArgs e)
         const string styleFormat =
           "<LINK href='\"{0}\"' type='\"text/css\"' rel='\"stylesheet\"'>";

         string linkText;
         linkText = String.Format(styleFormat, StyleSheetPath);
         StyleSheet.Text = linkText;        

In your case use name from request.query string

LVL 39

Accepted Solution

Pratima Pharande earned 500 total points
ID: 38739075
<link id="MyStyleSheet" rel="stylesheet" type="text/css" runat="server" />
</head>Then in your Page_Load, simply add a "href" attribute as below:

 Collapse | Copy Code
Sub Page_Load(Sender As Object, E As EventArgs)
 If Not (IsPostBack)
 End If
End Sub


Author Comment

ID: 38739678

Thanks for the response.

I have 2 stylesheets for Default.aspx .

I want to be able to select css1 or css2  based on entry
to default.axpx by way of default.aspx?product=a or default.aspx?product=b


Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now