Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

how to specify relate path from application root

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben Daniel - 13 Oct 2007 09:29 GMT
Hi all,

I think this question should be fairly common but I couldn't find any
existing answers in the forums.

I have a Master Page that refers to uses some client scripts like so:

<script language="javascript" type="text/javascript" src="Scripts/
Browser.js" />
<script language="javascript" type="text/javascript" src="Scripts/
Common.js" />

So any pages that inherit from this master page will automatically use
these scripts. And it works fine for pages in the application's root
directory BUT but all the pages I have under an \Admin\ directory
don't work as it tries to find the scripts under /WebsiteRoot/Admin/
Scripts/ instead of /WebsiteRoot/Scripts/

It seems I can't use "~" either! e.g. src="~/Scripts/Browser.js"

I reckon this would have to be a common problem encountered by asp.net
developers! So I'm desperate to find out how others (and how I can)
get around this problem.

Thanks in advance, Ben
Michael Nemtsev, MVP - 13 Oct 2007 09:58 GMT
Hello Ben,

why not to specify the full path to your files from the root directory?

---
WBR,
Michael  Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour 

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

BD> Hi all,
BD>
BD> I think this question should be fairly common but I couldn't find
BD> any existing answers in the forums.
BD>
BD> I have a Master Page that refers to uses some client scripts like
BD> so:
BD>
BD> <script language="javascript" type="text/javascript" src="Scripts/
BD> Browser.js" />
BD> <script language="javascript" type="text/javascript" src="Scripts/
BD> Common.js" />
BD> So any pages that inherit from this master page will automatically
BD> use these scripts. And it works fine for pages in the application's
BD> root directory BUT but all the pages I have under an \Admin\
BD> directory don't work as it tries to find the scripts under
BD> /WebsiteRoot/Admin/ Scripts/ instead of /WebsiteRoot/Scripts/
BD>
BD> It seems I can't use "~" either! e.g. src="~/Scripts/Browser.js"
BD>
BD> I reckon this would have to be a common problem encountered by
BD> asp.net developers! So I'm desperate to find out how others (and how
BD> I can) get around this problem.
BD>
BD> Thanks in advance, Ben
BD>
Roland Dick - 13 Oct 2007 11:42 GMT
Hi Ben,

Ben Daniel schrieb:
> I have a Master Page that refers to uses some client scripts like so:
>
[quoted text clipped - 6 lines]
>
> It seems I can't use "~" either! e.g. src="~/Scripts/Browser.js"

That's right, "~" is an ASP.NET expression and only works in ASP.NET
controls.

I faced this problem recently, and I simply added an ASP.NET Literal
control instead of the HTML tag and set the text of the literal to the
complete HTML tag in code behind. Depending on the request, it adds
"../" in front of the path.
This was for an embed-Tag to embed a flash file, but I would think it
also works for a JS reference.

Hope this helps,

Roland
Mark Rae [MVP] - 13 Oct 2007 11:45 GMT
> This was for an embed-Tag to embed a flash file, but I would think it also
> works for a JS reference.

It does.

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Ben Daniel - 14 Oct 2007 03:46 GMT
Thanks for your help everyone.

What I ended up doing was looking at the code behind the asp:image
control to see how it resolves the url in the ImageUrl property. It
calls a ResolveClientUrl function defined in Control. So I ended up
just doing this:

<script language="javascript" type="text/javascript" src="<%=
ResolveClientUrl("Scripts/Browser.js") %>" />
<script language="javascript" type="text/javascript" src="<%=
ResolveClientUrl("Scripts/Common.js") %>" />

Which works a treat. Thanks anyway.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.