Quantcast
Channel: All About SharePoint » vs2010
Viewing all articles
Browse latest Browse all 31

Create an AdditionalPageHead control packed into a Feature in Visual Studio 2010

$
0
0

It did take me a while to understand how could I package a solution by VS 2010.

I use JQuery UserControl as an example and assume you have JQuery Library installed already

1. First, create an empty SharePoint project

image

Choose deploy as farm solution

2. Add new feature by right click the Feature Folder, we will create a Site Collection Feature

image

3. Create 2 Mapped Folders

image

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

image

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"/>

</Elements>

8. Now in your feature you should see like

image

9. Your Solution List should look like

image

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

 image

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

image

image

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

image

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



Viewing all articles
Browse latest Browse all 31

Trending Articles