Master Page with CSS link and Javascript Url problem

H

homawong

In the header section of the master page I have

<script src="JavaScript/MyScript.js"></script>

<link href="CSS/MyCSS.css" type="text/css" rel="stylesheet" />

Since both of them are relative url, when the client request for a page
in a different directory other then the one master page locate will
break faild to load the css and script.

It is possible to do with absolute url but it is fagile. And during
development the project is under a virtual directory or in a file
system so "/CSS/MyCSS.css" doesn't work.

For script, a get around solution is to load the file from code behind,
but I can't find a way to do that with CSS, not to say this way is
ugly.

Another solution is using skin, but I'm not sure the designer will
happy with it. :)

Homa
 
C

clintonG

There's new classes in 2.0. Here is a commented dump of some code...

#region HTML Head Section...
//NOTE: THESE METHODS ARE FUNCTIONAL BUT COMMENTED OUT UNTIL
NEEDED

// Add meta tags
//HtmlMeta meta1 = new HtmlMeta();
//meta1.Attributes.Add("description", "blah blah blah");
//HtmlHead head = (HtmlHead)Page.Header;
//head.Controls.Add(meta1);

//// Add style sheets
//HtmlLink link1 = new HtmlLink();

//((HtmlHead)Page.Header).Controls.Add(link1);

//link1.Href = "~/StyleSheets/TestInheritence.css";
//link1.Attributes.Add("rel", "Stylesheet");
//link1.Attributes.Add("type", "text/css");

// Add javascript files
//HtmlLink link2 = new HtmlLink();

//((HtmlHead)Page.Header).Controls.Add(link2);

//link2.Href = "Scripts.js";
//// older browsers
//link2.Attributes.Add("language", "JavaScript");
//// newer browsers
//link2.Attributes.Add("type", "text/JavaScript");
#endregion


<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top