473,513 Members | 2,563 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 12213
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
2081
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
24356
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
7259
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,...
0
7535
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...
1
7098
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...
0
7523
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
5683
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,...
0
4745
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
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.