Solved

How to select stylesheet by url

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

My default  page is referenced as follows during testing:
http://localhost:xxxx/default.aspx?/products=a

http://localhost:xxxx/default.aspx?/products=b

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,
Isaac
0
Comment
Question by:TechIsaac
  • 2
3 Comments
 
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)
   {
      if(!IsPostBack)
      {
         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


refer
http://odetocode.com/articles/82.aspx
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 38739075
<head>
<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)
  MyStyleSheet.Attributes.Add("href","/css/flostyle.css")
 End If
End Sub

refer

http://www.codeproject.com/Articles/8961/Dynamically-set-a-link-to-a-CSS-file-in-ASP-NET
0
 

Author Comment

by:TechIsaac
ID: 38739678
Hi,

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

Isaac
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

756 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