Wednesday, February 22, 2006

Sharepoint and AjaxPro

I've been pretty anxious to try and get Ajax working with some of the work that I do in Sharepoint. A couple of days ago I was finally assigned a task that screamed Ajax. Since this is the first project on our server that needed Ajax, I had to do all the setup for it. After downloading the latest dll for AjaxPro, I got started trying to setup it up. Here are the steps you follow

  1. Install the AjaxPro.dll into the GAC or the bin folder (your choice)
  2. Add the Ajax HTTPHandler to each virtual directory's web.config

    <add verb="*" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro, Version=6.7.20.1, Culture=neutral, PublicKeyToken=4735ae9824c7d3ec"></add>
  3. Call the register command
    AjaxPro.Utility.RegisterTypeForAjax(typeof(MyPage), this.Page);
  4. Make a Ajax call with JavaScript

    try
    {
    window.attachEvent("onload", new Function("AjaxUserInfoInit();"));
    }
    catch(ex)
    {
    //Do Nothing
    }


Source: http://www.codeproject.com/Ajax/AjaxNetProExample.asp

So after getting everything configured, I tried loading my SharePoint portal and I started getting security errors for AjaxPro. Apparenty the above blog does not have code access security (or just didn't bother to mention it) setup on his server. For my setup, the best way to get the AjaxPro.dll the permissions it needed was to put it in the GAC (not always the safest way to do things). So after trying to load the portal again, I started getting an error saying that it couldn't locate the AjaxPro.dll. So after some googling, I found an article that mentions that if the dll for an HTTPHandler is in the GAC, the full strongnamed assembly name should be used in the HTTPHandler tag instead of just the assembly file name.

Soure: http://www.codeproject.com/aspnet/exploresessionandcache.asp

Once again I'm trying to load the portal and I get an error about how the AjaxPro assembly does not allow partially trusted callers to access it. So I downloaded the source code, compiled it with a strong name, add the AllowPartiallyTrustedCallersAttribute, redeployed the dll, and voila!!! My portal is once again serving Sharepoint sites. Now I can start writing the code to use the AjaxPro.dll.

Thursday, February 02, 2006

Custom Control

I created a simple web custom control that had a textbox as part of of its control collection. For some reason, the textbox would loses its value after a postback, which I assumed was because the textbox was loosing its viewstate (or couldn't find it). I searched a couple hours before I found INamingContainer. If you add INamingContainer as an interface to your custom control, the textbox will magically be able to maintain its viewstate after each postback.