SharePoint 2007 Web Parts and Telerik. Not the holy of holies.

By ipoipo

I have been using Telerik’s controls in WSS Web Parts since late 2006. When they introduced RadControls for AJAX, I jumped onto the bandwagon, right there with the rest of them being carted to the guillotine. Telerik named these controls “Prometheus” after the Titan who gave humans fire, and who caused Zeus to visit upon us a certain “Pandora” – she of the B.O.X. Commenting further on the choice of name, I thought it more apt to refer to it as “Sysiphus”, he of rock-up-the-side-of-mountain-pushing fame.

But I digress. Telerik’s 2008 Q1 RadControls for AJAX are not quite ready for WSS/SP Web Parts. The RadAjaxManager, RadAjaxPanel and RadAjaxLoadingPanel combo does not seem to be able to operate within WSS.

If you really, really want to use the RadAjaxPanel, make sure that you add it to the Page.Items collection in a base class for your web parts, similarly to adding the MSFT ScriptManager:
/// <summary>
/// Oninit fires before page load. Modifications to the page that are necessary to support Ajax are done here.
/// </summary>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//get the existing ScriptManager if it exists on the page
aspAjaxManager = ScriptManager.GetCurrent(this.Page);
if (aspAjaxManager == null)
{
//create new ScriptManager and EnablePartialRendering
aspAjaxManager = new ScriptManager();
aspAjaxManager.ID = "AspAjaxManager1";
aspAjaxManager.EnablePartialRendering = true;
// Fix problem with postbacks and form actions (DevDiv 55525)
Page.ClientScript.RegisterStartupScript(typeof(AjaxBasePart), this.ID, "_spOriginalFormAction = document.forms[0].action;", true);
//tag:"form" att:"onsubmit" val:"return _spFormOnSubmitWrapper()" blocks async postbacks after the first one
//not calling "_spFormOnSubmitWrapper()" breaks all postbacks
//returning true all the time, somewhat defeats the purpose of the _spFormOnSubmitWrapper() which is to block repetitive postbacks, but it allows MS AJAX Extensions to work properly
//its a hack that hopefully has minimal effect
if (this.Page.Form != null)
{
string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
{
this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
}
//add the ScriptManager as the first control in the Page.Form
//I don't think this actually matters, but I did it to be consistent with how you are supposed to place the ScriptManager when used declaritevly
this.Page.Form.Controls.AddAt(0, aspAjaxManager);
}
}
if (telerikAjaxManager == null)
{
telerikAjaxManager = new RadAjaxManager();
telerikAjaxManager.EnableAJAX = true;
telerikAjaxManager.EnableEmbeddedScripts = true;
telerikAjaxManager.ID = "RadAjaxManager1";
telerikAjaxManager.Enabled = true;
//this.Page.Form.Controls.Add(telerikAjaxManager);
this.Page.Items.Add(typeof(RadAjaxManager), telerikAjaxManager);
}
}

Sorry about the indentation! Kind of sucks, doesn’t it?

But I digress. Feel free to contact me if you want to get it working.

Ipo-Ipo.

Tags: , ,

2 Responses to “SharePoint 2007 Web Parts and Telerik. Not the holy of holies.”

  1. brock Says:

    Has this gotten any better? Or is it still a mess?

    If better, have any good examples to look at????

    Thanks !

    Brock.

  2. ipoipo Says:

    Hey Brock,
    Tell me what you need. I’m freelancing now :-) .
    Ipo-Ipo

Leave a Reply