Dynamically add the stylesheet(.CSS file)

V

VSK

Hi,

Iam looking for a way to dynamically add the stylesheet.

I have all the .aspx pages extend from a CommonPage.cs which extend from
System.Web.UI.Page.

Now i want a way to detect the browser(netsacpe/ie) and load the curr .css
file in CommonPage so that it applies to all the pages which extend from
commonpage.

Is there a way i can do.

any inputs will be helpful

Thx
VSK
 
S

S. Justin Gengo

VSK,

I think the easiest way would be to turn the style tag into a server side
control.

Set your style tag to look like this (with the href set to a default style
sheet):

<LINK id="StyleTag" runat="server" rel="stylesheet" type="text/css"
href="http://localhost/lab/styles.css">

Please note that I've added the attributes: id and runat to the tag.

Now in the code-behind page declare a matching object for the "StyleTag" id
like this:

Protected StyleTag As System.Web.UI.HtmlControls.HtmlGenericControl

Now you can use the StyleTag object to set any attribute from the
code-behind page.

In order to do what you want (change the href) you would use code like this:

StyleTag.Attributes.Add("href", "http://localhost/lab/NewStyles.css")


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
V

VSK

Thanks a lot!

S. Justin Gengo said:
VSK,

I think the easiest way would be to turn the style tag into a server side
control.

Set your style tag to look like this (with the href set to a default style
sheet):

<LINK id="StyleTag" runat="server" rel="stylesheet" type="text/css"
href="http://localhost/lab/styles.css">

Please note that I've added the attributes: id and runat to the tag.

Now in the code-behind page declare a matching object for the "StyleTag" id
like this:

Protected StyleTag As System.Web.UI.HtmlControls.HtmlGenericControl

Now you can use the StyleTag object to set any attribute from the
code-behind page.

In order to do what you want (change the href) you would use code like this:

StyleTag.Attributes.Add("href", "http://localhost/lab/NewStyles.css")


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top