Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to select stylesheet by url

Posted on 2013-01-02
3
Medium Priority
?
208 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
[X]
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
3 Comments
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 2000 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

730 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