473,786 Members | 2,672 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 12227
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
2095
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
6563
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
1524
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
24416
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
5092
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
9650
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
10164
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
10110
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
8992
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...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6748
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
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
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.