Wednesday, April 24, 2013

Create an AdditionalPageHead in SharePoint

Hi, here I am going to explain how we can add an additional page head in sharepoint page. It should come as a feature in sharepoint and code should be in an usercontrol.


1. First, create an empty SharePoint project

 
Choose deploy as farm solution 2. Add new feature by right click the Feature Folder, we will create a Site Collection Feature



3. Create 2 Mapped Folders
 

4. In JQueyTest.JS just have a simplt JQuery Script

$(document).ready(function () {
    $("a").click(function (event) {
        alert("Thanks for visiting!");
    });
});

5. the code in your ascx

<%@ Control Language="C#" ClassName="Ken.Test.JQuery" %>
<script type="text/javascript" src="/_layouts/Ken.Test.JQuery/JQueryTest.js"></script>

6. Create an empty element file that can reference our user control

 

7. In the Elements.xml file should look like

  <?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="
http://schemas.microsoft.com/sharepoint/" >
  <Control

Id="AdditionalPageHead"
ControlSrc="~/_controltemplates/Ken.Test.JQuery/Ken.Test.JQuery.ascx"
Sequence="12"/>

8. Now in your feature you should see like

 


9. Your Solution List should look like

10. Now if we click the Package button, then go to Bin\Debug folder, there is a WSP has been created. Rename the extension to .CAB file, then you can double click to see all files in the package



 11. If we deploy now, it will deploy the dll to the GAC which is not required. To remove the GAC deployment we have to modify the Package file 12. Now we need to double click the Package.package, then click the Manifest button and Click the “Overwrite …” to manually remove the Assemblies part

 


13. All ready to go! Click the deploy button and then go to your test page. If you click any link you will get
an alert box

 

14. If you found it not working, here is some tips to find what is wrong

A. Check your site collection feature to see if the feature has been actived

B. Right click the page and view source to see if your user control is there

C. Check the 14 folder to make sure your feature, user control and script is there

D. Make sure the element file point to the right path or name

Thanks for reading. Please give your comments to improve myself.

No comments:

Post a Comment