Alright, here is a new topic for all of you guys need to include AJAX-functionality into your SharePoint Webparts. Just to say it right away: It is a long and anoying way - but when you finally got your AJAX enabled webpart up and running - your feeeeeeeelllll great!!!
So, lets's keep it short... these are the steps you need to get the Microsoft AJAX Extensions running on your SharePoint installation:
- Download and Install the Microsoft ASP.NET AJAX Exentsions from http://www.microsoft.com/downloads/details.aspx?FamilyID=ca9d90fa-e8c9-42e3-aa19-08e2c027f5d6&displaylang=en
- Follow the steps posted from Mike Ammerlaan to configure the web.config file(s) of your SharePoint Web Application - I recommend to do only the web.config bits and pieces explained on this blog: http://sharepoint.microsoft.com/blogs/mike/Lists/Posts/Post.aspx?ID=3
- As you know, ASP.NET AJAX Framwork needs a Script Manager Object on each side hosting AJAX functionality. Even if the following Function works for most cases, I recommend you put the ScriptManager to your Master Page(s) - I really do. If you dont want to, you can try the following method (call it during your CreateChildControls activity to ensure that at least one Script Manager is present and registred):
private void EnsureScriptManager(){
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
if (scriptManager == null) {
scriptManager = new ScriptManager();
scriptManager.EnablePartialRendering = true; this.Controls.AddAt(0, scriptManager);
}
}
Et voila - AJAX is ready to be used... but one thing is left to say concerning the Update Panel (which you will most probably use):
- To fix another issue with SharePoint and the Update Panel, I wrote another function to ensure this fix. Same as the previous function you can call it during the CreateChildControls method:
public static void EnsureUpdatePanelFixups(WebControl Parent)
{
// PostBack Fix
// Found here: http://www.capdes.com/2007/02/microsoft_office_sharepoint_se.html
Parent.Page.ClientScript.RegisterStartupScript(typeof(WebControl), "PostbackFix", "_spOriginalFormAction = document.forms[0].action;", true);
// Panel Fixup
if (Parent.Page.Form != null)
{
if (Parent.Page.Form != null)
{
string formOnSubmitAtt = Parent.Page.Form.Attributes["onsubmit"];
if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
{
Parent.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
}
}
}
}
Hope that helps to give you a first go on Microsoft APS.NET AJAX-enabled Webparts! As you will see, there are more traps and unbelievable shity things you will encounter during your AJAX implementation - but you will finally be very very pleased with the new User Experience!
Have FUN