473,503 Members | 12,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmatically 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="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.

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 12209
You can use the RegisterClientScriptInclude 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="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.

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...@topscene.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...@yahoo.yabbadabbadoo.comwrote:
You can use the RegisterClientScriptInclude 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="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.
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.RegisterStartupScript(), 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...@yahoo.yabbadabbadoo.comwrote:
You can use the RegisterClientScriptInclude 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="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.
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.RegisterStartupScript(), 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...@yahoo.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...@yahoo.yabbadabbadoo.comwrote:
You can use the RegisterClientScriptInclude 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="javascript" type="text/javascript"
src="MyCodeFile.js"></script>
This includes my externaljavascriptcodefilefor 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.RegisterStartupScript(), etc...I use
it to register scripts located in my externaljavascriptfile. 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
2079
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...
3
1496
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...
1
6547
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...
2
1389
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">...
1
4909
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...
2
1507
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...
3
4218
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...
29
24355
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...
8
5076
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...
0
7098
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...
0
7470
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...
0
5604
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,...
1
5026
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...
0
3186
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...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
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 ...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
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...

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.