473,785 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Master Page with CSS link and Javascript Url problem

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

Nov 19 '05 #1
2 2038
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.Attribute s.Add("descript ion", "blah blah blah");
//HtmlHead head = (HtmlHead)Page. Header;
//head.Controls.A dd(meta1);

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

//((HtmlHead)Page .Header).Contro ls.Add(link1);

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

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

//((HtmlHead)Page .Header).Contro ls.Add(link2);

//link2.Href = "Scripts.js ";
//// older browsers
//link2.Attribute s.Add("language ", "JavaScript ");
//// newer browsers
//link2.Attribute s.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/

<ho******@gmail .com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
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

Nov 19 '05 #2
Thank you, it works, so I'll probably stick with this solution for now.

Nov 19 '05 #3

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

Similar topics

20
3374
by: M.Siler | last post by:
Let me first by saying I am NOT a .net programmer, but am very skilled with ASP, JavaScript, HTML, DHTML, Flash development. I've been reading through posts here about Frames vs. Master Pages and there seems to be the thought of why use Frames when you can use a Master Page? How does a Master Page only update a section without re-displaying the entire page. We have a site that has some small swf banners for lack of a better term that we...
0
1720
by: damiensawyer | last post by:
Hello all, I'm very new to all of this. I have a theme and a skin (the standard ones). I have a standard master page which is holding a custom ascx which has a treeview in it. Can someone please point me in the right direction to bind a theme to the treeview? The 'theme' tag is on the <%@ page %> directive... however neither my master page or ASCX files use this. They use <%Master%> and
6
2864
by: Naveen K Kohli | last post by:
I have couple of javascript files that need to be referenced for each content page. So I am trying to put them on Master page. The problem is that content pages are not on one level of the site. I have been trying to find a way to specify path to these JS files so that the actual path to these files correctly gets applied on the path at every level of the folder hierarchies. So far no luck... <script languaage=javascript...
0
1069
by: Nick Stansbury | last post by:
I'm experiencing a weird problem with master pages in VS 2005 - in short when the master page is open in design view in visual studio all other webforms that use that master display correctly when opened in design view. However, if the master page is not open in design view, then webforms opened in design view don't display correctly at all. Here are the specifics: My master page has the following lines of html: <head runat="server"...
4
8936
by: Greg | last post by:
I'm guessing the problem I'm having has something to do with Master Pages or DetailsView because the exact same code works fine on a page without a Master Page and DetailsView controls. The problem is, when the javascript fires on the txtDateRequiredOut TextBox in IE, I get "Error on Page" in the status bar and the error says: "Object Expected". Viewing the source of the page while running shows a link created properly for the linked...
2
7027
by: SR | last post by:
I have started a web site using ASP.NET 2.0. I would like to centralize all of my classes in a StyleSheet but I cannot figure out how to link the StyleSheet to a Content Page since there is no header. I tried to put the link tag in the Master page, but the classes are not recognized in the Content Page. How do I use a StyleSheet with the Content Page? TIA
2
2574
by: n# | last post by:
I have an old existing website with a Header/ Left Hand Menu and a iframe as the main body content, adjacent to the menu. So for every click on the menu item, I used to load a aspx page on the iframe and hence i am not loading the entire menu and header for each request. When I try and port the above model to Master Page 1) The menu ( I thot of having the Menu Web control), Header would be moved to the master page.
5
12227
by: Joey | last post by:
I have the following in the head section of the ASPX page for my master page: <script language="javascript" type="text/javascript" src="MyCodeFile.js"></script> This includes my external javascript code file for my master page and all subscribing pages. But I ran into a problem. This only works for pages in the root directory of the site. The (relative) path is wrong for pages in other folders on the website.
0
2752
by: dixonjm | last post by:
Hi, I have a master page & various pages that will use this master page. Each content page will have a CSS & JS file which will be named the same as the content page. When I try to load the CSS & JS files using the code behind of the content page, my buttons aren't rendered and Im not sure why? Here is the code for my content page - Properties.aspx:- <%@ Page Language="C#" AutoEventWireup="true" Title="Properties"...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.