views:

1179

answers:

3

Hello all I have a problem. I have a masterpage that all of my Content pages inherit from. Within this masterpage I have a script tag pointing to the javascript file folder "~/Scripts/validation.js"

On my content pages I use different usercontrols that require the use of many of the functions within the validation.js file however if I dont put the tag and the javascript functions within a contentholder on the contentpage the usercontrols do not see these functions and I get errors like "OnNameValidation" is not defined.

Of course I can copy the javscript code into all of the pages but that's 30+ pages and a maintenance nightmare if I find a bug in one of the javscript functions.

So the question (if you haven't already figured out from my long dissertation) is how can I declare the script tag with the path to the validation.js file so that contentpages and their usercontrols etc. can access the functions/code.

Thanks in advance.

A: 

What you are trying to do should work, so I suspect that the path to your javascript file is wrong (without seeing your html code I can only assume). Keep in mind that you can only reference the javascript file like this: "~/Scripts/validation.js" if you have the link in a HEAD runat="server" tag. Without the runat="server" it won't find the file. You would have to do something like "../scripts/validation.js"

As a test I would try to call your javascript function in the masterpage, so you can rule out a bad file reference.

A: 

I picked up this tip from ScottGu here.

Add this to you user control which enables Intellisense in user controls but always evaluates false:

<% if (false) { %>
   <script src="/Scripts/validation.js" type="text/javascript"></script>
<% } %>
Even Mien
A: 

The path you are assigning for your js file is probably not matching in all the pages.

script src="../JavaScript/Scriptaculous/scriptaculous.js"

It should have something like above this if you have separate folder for Scripts, MasterPages, Pages & Controls.

Ravia