Sorry it took me so long but I've finally had a chance to post my code and slides from this past Philly.Net Code Camp.  Thanks for all that attended, hopefully I showed everyone in the audience how easy it is to integrate AJAX, jQuery and Silverlight.

If anyone has any follow up questions, please let me know and I will gladly help out where I can. 

 

Here are the goods:  PhillyDotNet_Code Camp_Moss_Ajax_jQuery_Silverlight.zip


Tony Testa posted on March 15, 2009 03:48

A few days late but I finally got to posting my code/slides for the March Office Geeks we had on March 10th.  I've zipped up the code that I went over during the presentation which will show you some of the ways you can incorporate MS AJAX and jQuery into your SharePoint sites.

 

20090310_OfficeGeeks_TonyTesta_AJAX_JQuery.zip


I've spoken about this a few times in my presentations on the topic, but I don't think I ever blogged about it.  Basically to get ASP.NET AJAX to fully with with SharePoint 2007, you need to include some Javascript "fix" code which allows the ASP.NET AJAX to function properly. 

According to Microsoft, the reason for this code is the following "For ASP.NET controls that use the JavaScript _doPostBack() function to commit changes, a regular full-page postback event may occur even when the Web Part is inside an UpdatePanel control. Windows SharePoint Services 3.0 and ASP.NET AJAX cache certain form actions, which can cause a conflict between SharePoint and ASP.NET AJAX. To change this behavior, you must add code to scripts that are running in Windows SharePoint Services 3.0"

Below is the code you'll need to include in your Web Parts.

private void EnsurePanelFix()
{
   if (this.Page.Form != null)
   {
     String fixupScript = @"_spBodyOnLoadFunctionNames.push(""_initFormActionAjax"");
     function _initFormActionAjax()
     {
       if (_spEscapedFormAction == document.forms[0].action)
       {
         document.forms[0]._initialAction = 
         document.forms[0].action;
       }
     }
     var RestoreToOriginalFormActionCore = RestoreToOriginalFormAction;
     RestoreToOriginalFormAction = function()
     {
       if (_spOriginalFormAction != null)
       {
         RestoreToOriginalFormActionCore();
         document.forms[0]._initialAction = document.forms[0].action;
       }
     }";
   ScriptManager.RegisterStartupScript(this, 
     typeof(YOUR_WEBPART), "UpdatePanelFixup", 
     fixupScript, true);
   }
}
 
This code comes straight from Microsoft and you find it at http://msdn2.microsoft.com/en-us/library/bb861877.aspx
I've successfully been using the following code in my web parts without issue (for the life of me, I can't remember where I found it).
 
private void EnsureUpdatePanelFixups()
{
    if (this.Page.Form != null)
    {
        string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
 
        if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
        {
            this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
        }
    }
    ScriptManager.RegisterStartupScript(this, typeof(Demo01SimpleWebPart), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);
}
So the choice is yours as to which one to use. I've been sticking with the one I've found and have tested pretty thoroughly, but I'd like to think that the MS way is probably more "supported".

Posted in: Sharepoint  Tags: , ,

If anyone is in the VA Beach area on Feb 21st, stop by the Hampton Roads UG meeting.  I'll be presenting about how to use AJAX within your SharePoint Web Parts.  I presented on the same topic back at the Philly.Net Jan 2008 Code Camp and I think it went over really well, and one of the attendees runs the Hampton Roads UG, hence why I am presenting down there. 

Luckily for the attendees on thursday, I have updated the material to provide more "real world" examples, as well as some alternatives to using just using the straight MS ASP.NET AJAX framework to do AJAX.  I'll be including a few examples using jQuery, as well as the ICallbackHandler to do lightweight AJAX.  After attending Todd Bleekers' presentation on the same topic (I still feel mine is better of course!), he did turn me onto the ICallbackHandler idea.  Basically, it is a lightweight way to do AJAX style calls from your Web Parts, but as with everything AJAX related, it is to be used with caution. 

What I really want attendees to walk away with from this presentation, if they walk away with nothing else, is that SharePoint really is an "application platform" that you can develop on.  You can develop your apps using cutting edge technologies like AJAX and LINQ (my next upcoming presentation) for example, for those pieces of the app that need it.  But for the majority of your app, that 80% as they say, you can leverage what SharePoint comes with out of the box to achieve that 80%, and then use the other cutting edge technologies on that 20% of your app that really needs it.


I just got word earlier today that I got in to do a talk at the PhillyDotNet CodeCamp 2008.1.  It is going to be @ DeVry university instead of the standard Microsoft Malvern office.  This should will allow more people to attend as well as more talks!

Right now my talk is going to be on Incorporating AJAX into Sharepoint.  In my last talk I briefly demo'd a small AJAX enabled webpart within Sharepoint to show how easy it was to incorporate into Sharepoint.  I'm planning on expanding this out and showing more useful examples that people can use in existing sites.

I'll post more as I prepare for the event.

If your in the Delaware Valley area and want to share some knowledge I encourage you to sign up and do a talk!  Check out the PhillyDotNet site and contact them if your interested!

Posted in:   Tags: , ,
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017 Tony Testa's World