1

My ascx looks like this:

<SharePoint:ScriptLink ID="ScriptLink1" runat="server" Name="/_layouts/1033/MyProject/js/test.js"/>
test: <input id="example" /> 

test.js looks like this:

$(document).ready(function () {
    alert("test");
});

In MyProject I have a folder called js and in that folder I have test.js

I was under the impression that when I debugged my webpart it would pop up an alert taht said "test" but it does nothing. Am I doing something wrong here?

3

Do you have a reference to jquery on the page before the test.js include? Try using http://spc3.codeplex.com/wikipage?title=ClientScript&referringTitle=Home

Are there any script errors, is jquery loaded, try testing this before the alert:

if (typeof jQuery == 'undefined') {   
    alert('jQuery not loaded')   
}

Try adding this at the top of your include to make sure the include path is right

alert('test.js loaded')   

Is it a VS2010 project? You need to add one of the sharepoint mapped folders, say LAYOUTS, and make your folder stucture under that (can't start with a folder called js)

MyProject/LAYOUTS/1033/MyProject/js/test.js
  • Sorry, I left the jQuery part out. It is in my actual code, just didn't copy it over. I have not added the LAYOUTS folder yet so that is probably the problem. Is it just as simple as creating a folder called LAYOUTS or is there more to it? – Abe Miessler Apr 11 '11 at 15:15
  • For anyone interested in how to add Mapped Folders see this link: msdn.microsoft.com/en-us/library/ee231521.aspx – Abe Miessler Apr 12 '11 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.