[ACCEPTED]-ASP.Net Master Page and File path issues-runatserver
You could use a ScriptManager
:
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/jquery.js" />
</Scripts>
</asp:ScriptManager>
EDIT: If you absolutely need this in your 6 <head>
section, you could do something like:
<head>
<script type="text/javascript"
src="<%= Page.ResolveClientUrl("~/jquery.js") %>"></script>
</head>
EDIT 2: According 5 to the comments, if you are observing that
The 4 Controls collection cannot be modified because 3 the control contains code blocks (i.e. <% ... %>)
you 2 may need to change the above to use the 1 data-binding syntax:
<head>
<script type="text/javascript"
src="<%# Page.ResolveClientUrl("~/jquery.js") %>"></script>
</head>
Try <%#
instead of <%=
in Master page under head 5 section
<script type="text/javascript"
src="<%# ResolveUrl("~/YourScriptFolder/YourJQueryOrJavascript.js") %>">
</script>
Then in Code Behind of Master page 4 under Page_Load
Event
Page.Header.DataBind();
Now you are good to go with 3 either jQuery and JavaScript as well as 2 CSS just you need to change your path in 1 ResolveUrl
which file you want to handle CSS, JavaScript, jQuery.
If you're not going to us asp:ScriptManager 2 or absolute paths then you can do it like 1 this:
<script runat="server" type="text/javascript"
src='<%= Page.ResolveUrl("~/jquery.js") %>'></script>
I do not know whether you guys found the 21 solution to your problem or not. I was 20 facing the same problem and going nuts to 19 figure out why do I get "jQuery is undefined" error 18 on the plugins i use. I tried all the solutions 17 i get from the internet but no luck at all.
But, suddenly 16 something splash on my mind that may be 15 the script files should be in order. So, I 14 moved the jquery referece to first position 13 and everything start working like charm.
Remember 12 guys, if you're using any plugins with jquery, make 11 sure you use the folloing order of setting 10 reference to those fiels.
- reference to the jquery library
- reference to the other subsequent plug-in libraries and so on...
e.g.:
- "script src="js/jquery-1.3.2.min.js" type="text/javascript"...
- "script src="js/jqDnR.min.js" type="text/javascript"...
- "script src="js/jquery.jqpopup.min.js" type="text/javascript"...
- "script src="js/jquery.bgiframe.min.js" type="text/javascript"...
Always make 9 sure you must put the jquery reference to 8 first and then the subsequent libraries.
Hope, this 7 solves your problem especially when you 6 use with MasterPages. Its very strange 5 that it works no matter what order you use 4 when you don't use MasterPages but when 3 you do, then it somehow requres the proper 2 order.
Good luck and happy coding,
Vincent 1 D'Souza
Look at How to Run a Root “/”. This should fix all your issues 5 regarding unresolved .js
file paths. You basically 4 reconfigure the VS Dev server to run your 3 application as localhost:port/
as opposed to the regular 2 localhost:port/application name/
making name resolution work the same way 1 as it does on IIS.
For absolute path of the file for any page 1 use it following:
<script type="text/javascript" src="<%= Page.ResolveClientUrl("~/jquery.js") %>"></script>
<script type="text/javascript" src="/full/path/to/jquery.js"></script>
0
If this script tag goes directly to the 3 browser, then you unlikely can substitute 2 your site's root there. At least not on 1 the server. So you can:
- Deploy site to the root of domain name and use absolute paths (simplest solution).
- Insert this link with server control.
- Preprocess resulting HTML before sending it to the client (with HttpResponse.Filter).
You can also use <base> HTML tag:
<base href="http://www.domain.com"></base>
and 5 then all the links in header section are 4 relative to base address:
<script type="text/javascript" src="scripts/jquery.js"></script>
It's often useful 3 when you have multiple publishing destinations, like 2 local dev web server, demo server, etc. You 1 just replace that base URL.
<body>
<script language="javascript" src='<%= this.ResolveClientUrl("~/full/path/to/jquery.js") %>' type="text/javascript"></script>
</body>
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.