I put a function in an existing.js file (I tried two different files) so that the method would be available multiple places without repeating the code. I even created a simple function just to make sure it wasn’t something my function was messing up.
function doNothing() {
alert("Dammit.");
}
I can see the method in the intellisense list in my .ascx control, but as soon as I try to step into it, it fails.
Below is how I tried to reference the file and it seemed to work as far as seeing the methods, but it won’t work.
<script src="/javascript/messages.js" language="javascript" type="text/javascript"></script>
Any ideas? Any common mistakes that I may be making? It looks like it should work.
Note: when the methods are inside the .ascx file, they work fine, even with missing semi-colons.
Even if IntelliSense suggested
"/javascript/messages.js", the path will be wrong if your application is installed under a virtual directory instead of at the root of the Web site. For example, the full URL of the JavaScript file might be at http://www.example.com/myapp/javascript/messages.js, but because thesrcattribute starts with a/, the browser will access http://www.example.com/javascript/messages.js (without the “myapp” virtual directory) instead.If you’re using WebForms, you can change the
srcattribute as follows: