Sharepoint 2010 Custom Web Part with jQuery, ajax and .NET handler page

  1. Create empty SharePoint project

  2. Add new item and insert Visual Web Part

  3. Add SharePoint “Layouts” mapped folder

  4. Add new item and select application page template

  5. Rename application page name to “Handler1.ashx”

  6. Handler1.ashx page should be created under layouts/projectName folder

  7. Delete Handler1.designer.cs file

  8. Open Handler1.cs file

  9. Go to Tools>> Create GUID, select option no 5.  [Guid(“xxxxxxxxx-xxx….xxxx”)]  and click on copy.

10. Paste it before class name as shown below

      [Guid(“075DF61E-BD9B-4A5B-97A8-CA8A85B22727“)]
    public partial class Handler1: IHttpHandler
    {
       
        public bool IsReusable
        {
            get { throw new NotImplementedException(); }
        }

        public void ProcessRequest(HttpContext context)
        {

            context.Response.Write(“Hello” + SPContext.Current.Web.CurrentUser.Name + “: Welcome message from callback”);
        }
    }

11. Delete all content from Handler1.ashx file and paste the following line
    <%@ WebHandler
Class=”$SharePoint.Type.adbb9f6e-e244-4599-920b-08a4a694e418.AssemblyQualifiedName$”
%>

12. Save all files

13. Unload the project and edit project’s config file

14. Add the following line under first <PropertyGroup> element

     <TokenReplacementFileExtensions>ashx</TokenReplacementFileExtensions>

15. Save file and reload project.

Continue ReadingSharepoint 2010 Custom Web Part with jQuery, ajax and .NET handler page