473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamically add link to css stylesheet?

Is there a way to dynamically add a reference to the css stylesheet from the
codebehind similarly to the script registration features?

I was thinking of adding this code to a base class and inherit all my pages
from it so the css link below is added to each page automatically in the
<head> section....

<LINK href="/MyApp/Css/MyApp.css" type="text/css" rel="stylesheet">

Thanks, Dave.
Nov 18 '05 #1
3 11894
Hi Dave,

Putting something like the following in your page load event should do the
trick.

HtmlGenericControl link = new HtmlGenericControl("LINK");
link.Attributes.Add("rel","stylesheet");
link.Attributes.Add("type","text/css");
link.Attributes.Add("href","mydefinedstyle.css");
Controls.Add(link);

HTH

-Chris
~
http://weblogs.austinspad.com/caustin

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:6A**********************************@microsof t.com...
Is there a way to dynamically add a reference to the css stylesheet from the codebehind similarly to the script registration features?

I was thinking of adding this code to a base class and inherit all my pages from it so the css link below is added to each page automatically in the
<head> section....

<LINK href="/MyApp/Css/MyApp.css" type="text/css" rel="stylesheet">

Thanks, Dave.

Nov 18 '05 #2
Thanks!!!!

"Chris Austin" wrote:
Hi Dave,

Putting something like the following in your page load event should do the
trick.

HtmlGenericControl link = new HtmlGenericControl("LINK");
link.Attributes.Add("rel","stylesheet");
link.Attributes.Add("type","text/css");
link.Attributes.Add("href","mydefinedstyle.css");
Controls.Add(link);

HTH

-Chris
~
http://weblogs.austinspad.com/caustin

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:6A**********************************@microsof t.com...
Is there a way to dynamically add a reference to the css stylesheet from

the
codebehind similarly to the script registration features?

I was thinking of adding this code to a base class and inherit all my

pages
from it so the css link below is added to each page automatically in the
<head> section....

<LINK href="/MyApp/Css/MyApp.css" type="text/css" rel="stylesheet">

Thanks, Dave.


Nov 18 '05 #3
There are a few ways to go about this, but the easiest is to make your
head tag runat server, and add a literal control with your HTML.
in your HTML, make the head tag a server side object:

<html>
<head runat="server" id="head">
</head>
<body>
</body>
</html>

then in Page_Load:

Dim l As New Literal
l.Text = "<link rel=""Stylesheet"" type=""text/css""
href=""styles.css"">"
Me.FindControl("head").Controls.Add(l)

hope this works for you!

"Dave" <Da**@discussions.microsoft.com> wrote in message news:<6A**********************************@microso ft.com>...
Is there a way to dynamically add a reference to the css stylesheet from the
codebehind similarly to the script registration features?

I was thinking of adding this code to a base class and inherit all my pages
from it so the css link below is added to each page automatically in the
<head> section....

<LINK href="/MyApp/Css/MyApp.css" type="text/css" rel="stylesheet">

Thanks, Dave.

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: wjbell | last post by:
I have a piece of javascript I need to modify. Right now it changes a stylesheet in the document between style.css and no_indent.css. These are in the head of my document: <link rel=stylesheet...
1
by: Amir Eshterayeh | last post by:
Dear Friends I need to change the css file of my aspx files dynamically so users can choose their css file names and when page loads, it read css file name from database. I try to use...
4
by: Sergey Morkovkin | last post by:
Hi, guys! Does anyone knows the resolution of a problem when i need to insert <link> or <script> tag into HEAD section dynamically? I was trying few ways to do this: 1) RegisterClientScriptBlock...
1
by: JezB | last post by:
How can I dynamically change an external stylesheet link (or import) at runtime in server-side code ? I don't want to use a placeholder as in <link id="myTheme" rel="stylesheet"...
1
by: Jeremy | last post by:
Rather than hard-coding a reference to a css file in the HEAD of an aspx page, like this... <link rel="stylesheet" href="../css/admin.css" type="text/css"> How can I dynamically specify the...
2
by: Steve Franks | last post by:
What is the proper/best way to dynamically change the HTML written out to the browser based on the value from a variable in a code behind page? For instance, I have test.aspx.vb as a code behind...
5
by: maya | last post by:
hi, I'm using this script to switch stylesheets dynamically (in response to user input..) http://www.dynamicdrive.com/dynamicindex9/stylesheetswitcher.htm (sorry can't show url, am in...
2
by: ajayreddy2105 | last post by:
Hi All, I want to build the xpath expression dynamically in the xsl for for-each. Scenario is like this:: 1. From javascript I am sending the parameters to xsl. 2. In xsl I am taking those...
6
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.