Shival
Shival

Reputation: 274

Dynamic Style Sheet

Is it possible to link a style sheet from code behind.

I want to link stylesheet_1 when the current day is < 15 th and stylesheet_2 when current day is > 15 th

Thanks

Upvotes: 3

Views: 207

Answers (2)

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21376

You don't need to use code behind. Just use Javascript to link according to the date in onLoad() function in the body like the following example:

var d = new Date();
var fileName
if(d.GetDate()<15){
 fileName="stylesheet_1"
}else{
 fileName="stylesheet_2"
}
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", fileName)

  document.getElementsByTagName("head")[0].appendChild(fileref)

Upvotes: 2

abney317
abney317

Reputation: 8512

Haven't tested this, but I think it will work.

Put this in the head of the aspx page

<link href="stylesheet.css" rel="stylesheet" type="text/css" id="stylesheet" />

and then you can use the in the code behind to change it

stylesheet.Href = "stylesheet_1.css";

Upvotes: 0

Related Questions