Adding a CSS link to every page

G

Guest

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
 
D

David Jessee

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.
 
M

MWells

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
 

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,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top