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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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