Usercontrol access Javascript from a Content's Page's Master Page?

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.

Up vote 2 down vote favorite share g+ share fb share tw.

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 don't 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 Javascript code into all of the pages but that's 30+ pages and a maintenance nightmare if I find a bug in one of the Javascript 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. Asp.net javascript usercontrols master-pages link|improve this question edited Nov 23 '11 at 1:05Jonathan Leffler139k10108268 asked Mar 11 '09 at 0:07Coda302210 75% accept rate.

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.

I picked up this tip from ScottGu here. Add this to you user control which enables Intellisense in user controls but always evaluates false.

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.

I am currently doing this in my site by going to the Source code on the master page and putting the following in the head and outside of the ContentPlaceHolder.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions