Solved

How to select stylesheet by url

Posted on 2013-01-02
3
202 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Definitions and default visual studio colors 5 58
ADO.NET ENTITY DATA MODEL 3 30
Error in query expression 3 31
Web Form VB.Net  import CSV 4 17
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.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
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…

937 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

11 Experts available now in Live!

Get 1:1 Help Now