Solved

jquery and asp.net master page - broken reference

Posted on 2011-03-11
6
738 Views
Last Modified: 2012-05-11
This may be more of an ASP.NET masterpage problem, but it involves jquery and a jquery plugin, so I'm posted it in both places.

In my ASP.NET webapp (v3.5), when I started using masterpages I got strange javascripting behaviors and had to start using RegisterStartupScript and RegisterClientScriptBlock in the codebehind of master to solve the problems.

But I have 1 more js problem, possibly related. In one of my aspx pages (not master) I have these 2 js references:
<script type="text/javascript" src="Scripts/jquery-1.4.4.js" />
<script type="text/javascript" src="Scripts/putCursorAtEnd.js" />

Open in new window


Then in the aspx page it references a usercontrol that contains some jquery script that references the putCursorAtEnd.js. Again, before I started using masterpages everything worked perfectly. Afterward, the jquery executes fine but it can't find the putCursorAtEnd function. Behaves exactly as if that reference to the .js file were not there. Yet obviously the jquery js file is being seen because all the jquery stuff works fine.

When I tried, just for a test, to paste the entire contents of putCursorAtEnd.js at the end of jquery-1.4.4.js" , it works fine. That's not a good long-term solution, but it's worth noting.

Any ideas why the referenced putCursorAtEnd.js does not seem to be found?
0
Comment
Question by:SweatCoder
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:Mrunal
ID: 35114605
hi

you have to include these files in master page in head tag. this is preferable way to include js files.

Hope this solves your problem.
0
 
LVL 11

Author Comment

by:SweatCoder
ID: 35116724
mroonal: Same exact problem when I moved the js file references to Master. jquery works, putCursorAtEnd.js isn't recognized.

Other ideas?
0
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 500 total points
ID: 35131941
Use <script></script> instead of <script />
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 11

Author Closing Comment

by:SweatCoder
ID: 35132660
Albert,

That fixed it! But I can't understand why closing off the js script reference one way rather than another makes any difference. I thought they were identical for purposes of referencing a js file.
0
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 35133166
There are plenty of discussions going on, and there are explanations.
See http://stackoverflow.com/questions/69913/why-dont-self-closing-script-tags-work for example.

I just do it always with a closing tag. (learned the hard way...)
0
 
LVL 11

Author Comment

by:SweatCoder
ID: 35134815
Lots of grief over a little thing. :-)  Thanks again.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now