473,386 Members | 1,738 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,386 software developers and data experts.

Adding a .css to <head> tag from codebehind?

I'm inheriting from a custom page class instead of System.Web.UI.Page, and I
want to add a .css or .js link to the page's <head> tag. Can this be done?

I tried this using but it just adds it to the bottom of the page....I need
to somehow reference the <head> server-side?

HtmlGenericControl link = new HtmlGenericControl("LINK");
link.Attributes.Add("rel","stylesheet");
link.Attributes.Add("type","text/css");
link.Attributes.Add("href","/Css/Main.css");
Controls.Add(link);
Nov 19 '05 #1
2 1870
the supported method is to add a placeholder control in the header section,
that you can update in the code behind. you can also add a runat=server on
the header.

if you want to be tricky, you can walk the page controls collection, peek at
the html in the of generic controls that exist before the form control for
the <header> tag, and update the html.

-- bruce (sqlwork.com)

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
I'm inheriting from a custom page class instead of System.Web.UI.Page, and
I
want to add a .css or .js link to the page's <head> tag. Can this be done?

I tried this using but it just adds it to the bottom of the page....I need
to somehow reference the <head> server-side?

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

Nov 19 '05 #2
Bruce,

Just curious, what do you mean by supported method? I was trying to find
something on msdn about this. If you have a link, I'd be interested. Thanks,
Dave

"Bruce Barker" wrote:
the supported method is to add a placeholder control in the header section,
that you can update in the code behind. you can also add a runat=server on
the header.

if you want to be tricky, you can walk the page controls collection, peek at
the html in the of generic controls that exist before the form control for
the <header> tag, and update the html.

-- bruce (sqlwork.com)

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
I'm inheriting from a custom page class instead of System.Web.UI.Page, and
I
want to add a .css or .js link to the page's <head> tag. Can this be done?

I tried this using but it just adds it to the bottom of the page....I need
to somehow reference the <head> server-side?

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


Nov 19 '05 #3

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

Similar topics

0
by: Andrés Giraldo | last post by:
Hi! It's possible to register some script between the <head> and </head> actually I'm Using RegisterStartupScript and RegisterClientBlockScript, but it works on the body By the way... how...
15
by: Frances | last post by:
<html> <head> <script> function doIt() { var list = document.forms.product; var selItem = list.options.value; ^^^^^^^ </head>
10
by: Brian W | last post by:
Hi All, I have a web user control that, among other things, provides Print this page, and Email this page functionality I have this script that is to execute on the click of the asp:hyperlinks ...
6
by: Ken Varn | last post by:
I want to add my own custom <STYLE> section in the <HEAD> section of my ASP.NET page within a custom control. Can someone tell me how I can have my custom control add tags to the <HEAD> section of...
3
by: jsh02_nova | last post by:
Anybody know how to add a script block to the html <head> section programmatically without using the 'RegisterScriptBlock' functions? -- thx -jsh
7
by: ericgla | last post by:
I am creating a web app using asp.net 2.0 where all pages are based a single master page. On some of the aspx pages I need to add javascript to the head tag in order to use Google maps. I tried...
5
by: Arne | last post by:
I need literal controls in the <head> section of my page. I need to be able to load dynamic values in the head section. It works fine in ASP.Net 1.1, but Asp.net 2.0 gives a compile error. I need...
1
by: Frank | last post by:
I would like to create a custom control that generates everything that will be in the <head> </head> section. This would allow me to make changes on all pages withing a site in one location. ...
3
by: phpmel | last post by:
Hi guys, I have yet another question. I am working with this html form that uses a template. <head> //is greyed out //some greyed out <style >stuff is next <!-- InstanceEndEditable...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...

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.