+1 (866) 930-8356

We are experts on the entire Microsoft enterprise product stack. These are Microsoft technologies we regularly deploy. We provide real business value through strategic guidance, technical expertise, and knowledge transfer.

 

Most organizations share a core set of business needs. These solution categories apply across industries, helping line-of-business managers and the IT managers who support them apply genuine solutions to universal needs.

 

As an IT systems integrator, our expertise is putting all the pieces together to get the job done, so we never have to take “no” for an answer. We help organizations improve business productivity in any department.

 

We provide solutions customized to the needs of your industry. Whatever your industry or product, we can provide project, service, process, and content management solutions—to increase productivity and IT value.

 
Concurreny
Real Microsoft expertise. Real business value.

Add jQuery to SharePoint

In this article I’ll show you how to create a nice SharePoint 2010 wsp Feature that you can deploy to any SharePoint site you’d like, and when activated, it will “turn on” jQuery for all of your webs in the site collection (without editing the MasterPage)! Let’s get started:

Creating the Project

  1. In Visual Studio, create a new SharePoint 2010 “Empty SharePoint Project”
  2. Name it “jQueryFrameworkFeature”
  3. Enter your local site address and choose “Deploy as a farm solution” in the SharePoint Customization Wizard.

Prepping the Project

You should be looking at a new Empty SharePoint Project. Now, let’s prep the project:

  1. Right click on your jQueryFrameworkFeature project node in the solution explorer, choose “Add > SharePoint Mapped Folder…”
  2. Expand the “TEMPLATE” node, choose “CONTROLTEMPLATES” and click OK.
  3. In the Solution Explorer, right click the newly added mapped folder, “CONTROLTEMPLATES” and add a new folder named “jQueryFrameworkFeature”
  4. Add another SharePoint Mapped Folder again, this time chose TEMPLATEIMAGES

We now have our basic folder structure that we’ll need and so the overall project should now look like this:

The next thing we want to do is have a cool icon that will be used in our feature list in SharePoint to set it apart from the other generic looking features. I’ve created my own that will immediately scream jQuery! when you see it in the list:

Save the image above into your IMAGES/jQueryFrameworkFeature folder.

Adding the jQuery

The next thing that we’ll need to do is add a user control to our jQueryFrameworkFeature folder in our CONTROLTEMPLATES folder. Follow these steps:

  1. Right click on jQueryFrameworkFeature folder in our CONTROLTEMPLATES folder, and choose “Add > New Item…”
  2. Under SharePoint > 2010, select “User Control”
  3. Name it jQueryRef.ascx, click the Add button.
  4. Delete the jQueryRef.ascx.cs file (this will also delete the .designer file too, which is OK).
  5. Open the Source code view for the jQueryRef.ascx file and remove every single line of code except for the “<%@ Control …” line (should be the last line of code). You should now have something like this:
  6. Remove the CodeBehind=”jQueryRef.ascx.cs” property completely.
  7. Directly after the Control declaration line, add the following line of code:
    <script type=”text/javascript” src=”http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js “></script>
  8. Save, and then close this file.

Getting it on the MasterPage

So you might wonder how we’re going to get jQuery onto the MasterPage without editing it. Well as you’ve seen already, we’ve got a User Control with our jQuery reference sitting in it. Because of this, we can put this user control into one of the MasterPage’s content control areas, specifically the “AdditionalPageHead” area. Here’s how:

  1. Right click on your project, choose “Add > New Item…”
  2. In SharePoint > 2010 choose “Module”
  3. Name it “jQueryFrameworkModule”
  4. Within the module we’ve just added, remove the “Sample.txt” file.
  5. Open the elements.xml file and edit to look like this:

Creating the Feature

In the previous section, when adding the module, you may have noticed that it created a feature for us, named “Feature1.” We’ll use this to complete the process:

  1. Rename “Feature1″ to “jQueryFrameworkFeature”
  2. Double click on the first node of this feature to edit its properties. You should see in the “Item in the Feature” list on the right our “jQueryFrameworkModule” module.
  3. Enter, for the title, “jQuery Framework”
  4. Enter, for the description, “Enables the user of jQuery framework across pages in the current site collection.
  5. Change the Scope to “Site”
  6. In the properties window in the lower right, find the “Image Url” property, and enter the following URL
    jQueryFrameworkFeature/jQueryFrameworkFeature.gif

If you right click on your project and deploy you will now have jQuery in your SharePoint!

 

 
 

 
  • http://YourWebsite Brew

    Can you tell me how to add jquery scripts to a page? I’m new to SharePoint.
    Thanks,

  • http://softwarerevolution-onkara.blogspot.com Onkar

    Please can you tell me how to use object data model in sharepoint??

  • http://YourWebsite L01$Lan3

    Does this work in MOSS2007?

  • Pingback: Create own delegate control « Sharepoint. Kunskap. Upptäckter på resan.

  • Ka

    Hi,

    Thanks for the step by step and great blog post. Appreciate it.

    I have a query. You mentioned “If you right click on your project and deploy you will now have jQuery in your SharePoint!”

    Where do I see this Feature in SharePoint (like Activate this Feature via button (_layouts/ManageFeatures.aspx). AND how can I add a .js JavaScript file to use jQuery?

    Thanks in advance.

  • http://www.ratingsoft.com Alexander S.

    I’m interested how to use jQuery in my form too. What path (src=”") should I use in block, if jQuery’s already on site?

  • http://YourWebsite DG

    Hi,
    Thanks for the step by step and great blog post. Appreciate it.
    I have a query. You mentioned “If you right click on your project and deploy you will now have jQuery in your SharePoint!”
    Where do I see this Feature in SharePoint (like Activate this Feature via button (_layouts/ManageFeatures.aspx). AND how can I add a .js JavaScript file to use jQuery?
    Thanks in advance.

  • Peter

    I activated this feature on my Site Collection, but nothing happened (can’t see the 1.5.0 jQuery library included).

    The Master Page is customised but has the “AdditionalPageHead” feature. Perhaps another feature is taking-over.

    This is also an upgraded 2007 site.

  • Peter

    Your sample has an error:
    The control declaration “/_CONTROLTEMPLATES/jQueryFramework/jQuery.ascx” should be “jQueryRef.ascx”

Categories