By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,510 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,510 IT Pros & Developers. It's quick & easy.

Adding a CSS link to every page

P: n/a
I would like to add a CSS link to every page on my site - "<LINK
href="BLT.css" type="text/css" rel="stylesheet">".

This links needs to go in the <HEAD> of my page. I was hoping that I could
derive all my pages from a common base class, and that I could add this link
to each page's <HEAD> tag from the C# base class. Is this possible?

Is there an alternate way of adding this link to each page?

many thanks

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I'm going to assume that you're working with a code-behind model here. If
this is the case then the way the page behaves is that the actions are
determined by the Page class and then a second class is dynamically compiles
based on the design that is created in the editor.

Therefore the Base class for the page does not have any of the <title>
<meta> etc elements.
Here's what you CAN do, however......
The page class that is generated by the runtime parses the aspx document
into a control hierarchy. 99% of the time the resultant page has 3 controls
in it. a LiteralControl(0), a Form Control(1), and then another Literal
Control(2).

The text boxes, buttons, etc are parsed and become child controls of the
form control (control 1).

To se an Example of this, place a text box and a button on a page and for
the button;s event handler, do something like
Text1.Text = (LiteralControl)this.Controls[0]; (or you can place a
breakpoint somehwere and just inspect your class.)

so, directly, no.......however......

Since that first control is just a literal control, there's nothing stopping
you from changing its innerHMTL property...maybe placing some test right
after the <head> element :-) and there nothing that says you can't create a
class that derives from page that does this, and then have your code behinds
derive from that instead.

Now if you do this, one small bit of advice....place the new page base class
inside of another project (assembly) and reference that project form your
web app. I know this sounds strange....but sometimes the ide gets funny if
you try to design a web form whose base class is something other than
System.Web.UI.Page if that class is in the same assembly as the web project.
"Ron James" <Ro******@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
I would like to add a CSS link to every page on my site - "<LINK
href="BLT.css" type="text/css" rel="stylesheet">".

This links needs to go in the <HEAD> of my page. I was hoping that I could derive all my pages from a common base class, and that I could add this link to each page's <HEAD> tag from the C# base class. Is this possible?

Is there an alternate way of adding this link to each page?

many thanks

Nov 19 '05 #2

P: n/a
Ron,

Assuming the link is identical across all pages, and that all the pages
already exist, you might be better off with a project-wide search&replace
through VS.NET.

Something like

Search;

</head>

Replace;

<LINK href="BLT.css" type="text/css" rel="stylesheet">
</head>

Just a thought, in case the solution could really be that simple...

/// M
"Ron James" <Ro******@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
I would like to add a CSS link to every page on my site - "<LINK
href="BLT.css" type="text/css" rel="stylesheet">".

This links needs to go in the <HEAD> of my page. I was hoping that I could derive all my pages from a common base class, and that I could add this link to each page's <HEAD> tag from the C# base class. Is this possible?

Is there an alternate way of adding this link to each page?

many thanks

Nov 19 '05 #3

P: n/a
I had the same problem some time ago.
And developed the following:

http://nopaste.dotnet-expert.de/View.aspx?id=59

It´s works completely from code-behind. It´s not
neccessary to modify your aspx.

Hope it helps!
Cu Jens
"Ron James" <Ro******@discussions.microsoft.com> schrieb im Newsbeitrag
news:80**********************************@microsof t.com...
I would like to add a CSS link to every page on my site - "<LINK
href="BLT.css" type="text/css" rel="stylesheet">".

This links needs to go in the <HEAD> of my page. I was hoping that I
could
derive all my pages from a common base class, and that I could add this
link
to each page's <HEAD> tag from the C# base class. Is this possible?

Is there an alternate way of adding this link to each page?

many thanks

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.