Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Programmatically Include Link to External Javascript File In Master Page

Reply
Thread Tools

Programmatically Include Link to External Javascript File In Master Page

 
 
Joey
Guest
Posts: n/a
 
      06-04-2007
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?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      06-04-2007
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?
>
>

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      06-04-2007
On Jun 4, 7:49 pm, Joey <(E-Mail Removed)> wrote:
> 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"

 
Reply With Quote
 
Joey
Guest
Posts: n/a
 
      06-04-2007
On Jun 4, 1:31 pm, Peter Bromberg [C# MVP]
<(E-Mail Removed)> wrote:
> 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?

 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      06-04-2007
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]
> <(E-Mail Removed)> wrote:
> > 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?
>
>

 
Reply With Quote
 
Joey
Guest
Posts: n/a
 
      06-18-2007
On Jun 4, 3:39 pm, Peter Bromberg [C# MVP]
<(E-Mail Removed)> wrote:
> 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]
> > <(E-Mail Removed)> wrote:
> > > 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting the value of a Master page's control's property using a property of the Master page Nathan Sokalski ASP .Net 25 03-04-2010 03:42 AM
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
Include asp page in a master page namrehs ASP .Net 0 12-06-2007 05:38 PM
Can a master page be built from another master page Zeba ASP .Net 1 02-22-2007 10:55 AM
seeking servlet "Master" keep getting "Master/servlet/Master" not found. Tomcat 5.0.25 Doug McCann Java 1 08-05-2004 09:16 PM



Advertisments