473,799 Members | 3,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y Include Link to External Javascript File In Master Page

I have the following in the head section of the ASPX page for my
master page:

<script language="javas cript" 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.

I tried using src="/MyCodeFile.js", but that doesn't work. I
understand that if I was using a server control I could use src="~/
MyCodeFile.js".

So what is the best way to handle this?

Jun 4 '07 #1
5 12228
You can use the RegisterClientS criptInclude method
http://msdn2.microsoft.com/en-us/library/kx145dw2.aspx
if necessary, along with the ResolveUrl helper method.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Joey" wrote:
I have the following in the head section of the ASPX page for my
master page:

<script language="javas cript" 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.

I tried using src="/MyCodeFile.js", but that doesn't work. I
understand that if I was using a server control I could use src="~/
MyCodeFile.js".

So what is the best way to handle this?

Jun 4 '07 #2
On Jun 4, 7:49 pm, Joey <joey.pow...@to pscene.comwrote :
I tried using src="/MyCodeFile.js", but that doesn't work.
What the path of your web application is?

If something like http://localhost/MyApp/ then you should use src="/
MyApp/MyCodeFile.js"

Jun 4 '07 #3
On Jun 4, 1:31 pm, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yabbadabbadoo .comwrote:
You can use the RegisterClientS criptInclude methodhttp://msdn2.microsoft .com/en-us/library/kx145dw2.aspx
if necessary, along with the ResolveUrl helper method.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"Joey" wrote:
I have the following in the head section of the ASPX page for my
master page:
<script language="javas cript" 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.
I tried using src="/MyCodeFile.js", but that doesn't work. I
understand that if I was using a server control I could use src="~/
MyCodeFile.js".
So what is the best way to handle this?- Hide quoted text -

- Show quoted text -
Could you provide an example for how to do this?

I am familiar with ClientScript.Re gisterStartupSc ript(), etc...I use
it to register scripts located in my external javascript file. But how
do I register the file itself?

Jun 4 '07 #4
Joey,
You need to go back and read the MSDN page at the link I provided in my
previous response. If you still "don't get it, post again and somebody will
respond.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Joey" wrote:
On Jun 4, 1:31 pm, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yabbadabbadoo .comwrote:
You can use the RegisterClientS criptInclude methodhttp://msdn2.microsoft .com/en-us/library/kx145dw2.aspx
if necessary, along with the ResolveUrl helper method.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"Joey" wrote:
I have the following in the head section of the ASPX page for my
master page:
<script language="javas cript" 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.
I tried using src="/MyCodeFile.js", but that doesn't work. I
understand that if I was using a server control I could use src="~/
MyCodeFile.js".
So what is the best way to handle this?- Hide quoted text -
- Show quoted text -

Could you provide an example for how to do this?

I am familiar with ClientScript.Re gisterStartupSc ript(), etc...I use
it to register scripts located in my external javascript file. But how
do I register the file itself?

Jun 4 '07 #5
On Jun 4, 3:39 pm, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yabbadabbadoo .comwrote:
Joey,
You need to go back and read the MSDN page at the link I provided in my
previous response. If you still "don't get it, post again and somebody will
respond.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"Joey" wrote:
On Jun 4, 1:31 pm, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yabbadabbadoo .comwrote:
You can use the RegisterClientS criptInclude methodhttp://msdn2.microsoft .com/en-us/library/kx145dw2.aspx
if necessary, along with the ResolveUrl helper method.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Joey" wrote:
I have the following in the head section of the ASPX page for my
master page:
<script language="javas cript" type="text/javascript"
src="MyCodeFile .js"></script>
This includes my externaljavascr iptcodefilefor 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.
I tried using src="/MyCodeFile.js", but that doesn't work. I
understand that if I was using a server control I could use src="~/
MyCodeFile.js".
So what is the best way to handle this?- Hide quoted text -
- Show quoted text -
Could you provide an example for how to do this?
I am familiar with ClientScript.Re gisterStartupSc ript(), etc...I use
it to register scripts located in my externaljavascr iptfile. But how
do I register thefileitself?- Hide quoted text -

- Show quoted text -
I got it. Thanks for the link.

JP

Jun 18 '07 #6

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

Similar topics

1
2096
by: Andy Levy | last post by:
Hi I have an external .js file to my webpaage. Can i change the value of these variables from my htm page, so that they are changed for good. ie - i know this wont work, but it is an example. externalFile.js ------------- var alpha = "This is some text"
3
1508
by: sck10 | last post by:
Hello, I am using asp.net 2.0. I have an asp.net page that uses JavaScript to open a popup window. When I use the JavaScript with a content page that has a MasterPage, I get a "return" error associated with the JavaScript. I would prefer to keep the JavaScript in the ContentPage, but how would I do so? Thanks in advance, sck10
1
6565
by: anjud | last post by:
I have an external javascript file which contains a global variable - arrNames var arrNames=new Array(); arrNames="FirstName"; arrNames="LastName"; In my html page I had given the path of this external script file as <head> <script language="javascript" type="text/javascript" src="Common.js"></script>
2
1402
by: praveenmmohanan | last post by:
Hi..., I removed all the JavaScript code & put it in a file called abc.js from a HTML page. Now I tried to refer it in the HTML page like this : <script src="abc.js" type="text/javascript"> </script> It gives me "Object Expected" error. Where should the abc.js reside in the Web Project.
1
4921
by: elsheh | last post by:
Hi. Guys I use an XSLT style sheet to transform my xml document into html doc. I need to embed an external JavaScript file into html doc. The following line is used for this purpose: <script type='text/javascript' src='xxx.js'></script> Although, all files are allocated in a single directory, html doc. can’t import the JvaScript file You help is appreciated
2
1525
by: sssunny27 | last post by:
my question is:- the use of external javascript files has been supported in Netscape Navigator browser since which version? options are:- a) version 3.0 b) version 4.0 can somebody help me to find the answer
3
4234
by: gsuns82 | last post by:
HI all, I tried to read an array from an external javascript file called read.js,The array was declared & as well as defined with some values inside the <script> tag of a html file. For an instance: test.html: -------------- <html> <head> <script>
29
24424
by: FreshRob | last post by:
I have been trying to fix this issue the whole of today and have gotten no where. I am developing a new website, and wanted it to display a webpage in lightbox and have an external page added to the main page, both worked successfully apart, but it wasn't until I combined them that I have had an issue. My aim was to have ajax add the external page into a div and then load lightbox from that div, though that is where the problem lies as I can...
8
5095
by: kkshansid | last post by:
external javascript file not working on server <script type="text/javascript" src="../include/common.js"></script> while internal wrking fine <script language="JavaScript"> . . </script> i changed it to <script language="JavaScript"src="../include/common.js"></script> but still not working
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9543
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
10488
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...
1
10237
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
10029
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
9077
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
6808
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();...
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.