0

I have a master page with a reference to javascript file that is js folder. Both File and masterpage are in the root directory.

Many of my forms are in different folders Like

  Root>first>abc.aspx
  Root>second>def.aspx
  Root>second>anotherFolder>def.aspx

I kept the reference like this

      <script type="text/javascript" src="js/Check.js"></script>

I also tried src="<%= Page.ResolveUrl("~/js/Check.js") %>" and src="~/js/Check.js". While using Page.ResolveUrl and Server.ResolveUrl page shows error.

What i need to do so that any form in any directory get the reference of the file. I dont want to do ../ and ../../ in every form.

2 Answers 2

4
<script type="text/javascript" src="/js/Check.js"></script>

you can use "/" --> web site root

Sign up to request clarification or add additional context in comments.

4 Comments

Actual path is localhost:1500/AppName/js/Check.js and with "/" it references localhost:1500/js/Check.js. The error still holds.
are you using virtual directory?
Yes i m using virtual directory
also script reference is in my head tag
1

If you're running your Visual Studio's internal server for debugging then firstly remove the virtual folder it insists on using.

Do this by selecting the root of your site in VS Solution explorer, then right-click and choose "Properties Window" - in the properties change "Virtual Path" from your "AppName" to /

This virtual path plays havoc with all sorts of paths..I find that if i don't make this change in VS then when I DO get all my paths working they won't work when I put the site on a live server that isn't using a virtual site.

Then set your JS reference to <script type="text/javascript" src="/js/Check.js"></script> - using the root / in your src.

UPDATE

If you really want to keep the virtual folder then you can try this - using ResolveClientUrl():

First, add Runat="Server" to your <head>

<head runat="server" id="myhead">

<script type="text/javascript" src='<%=ResolveClientUrl("~/js/check.js") %>' />

7 Comments

good point. Thanks. is there another way without removing virtual folder i.e. by code
If you're not going to be putting it in a virtual directory on the server then i would strongly advise not trying to hack it. it gets VERY messy..
i will put this in iis virtual directory and then convert it to application.
Error as i described in question. "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)."
also script reference is in my head tag
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.