Best Approach To Adding Telerik Ajax Settings To SharePoint WebPart

This is the most effective way I have found to add the appropriate AJAX settings to a SharePoint WebPart. This differs from how you would add the settings within a normal ASP.NET context. There are a couple of assumptions that are placed within the code. Firstly, a Panel is going to be leveraged as the primary holder for a series of controls, and I am also going to call a recreate method for reliability of control recreation. This method should be called from the WebPart’s OnLoad event.

Using the below helper method:

[csharp]

 private void AddAjaxSettings()

{

RadAjaxManager current = RadAjaxManager.GetCurrent(Page);

AjaxSetting ajaxSetting = new AjaxSetting([This Is Your Panel].ID);

AjaxUpdatedControl newItem = new AjaxUpdatedControl

{

ControlID = [This Is Your Panel].ID,

LoadingPanelID = LoadingPanel.ID

};

ajaxSetting.UpdatedControls.Add(newItem);

current.AjaxSettings.Add(ajaxSetting);

ajaxSetting = new AjaxSetting(current.ID);

AjaxUpdatedControl ajaxUpdatedControl = new AjaxUpdatedControl

{

ControlID =  [This Is Your Panel].ID,

LoadingPanelID = LoadingPanel.ID

};

ajaxSetting.UpdatedControls.Add(ajaxUpdatedControl);

current.AjaxSettings.Add(ajaxSetting);

AjaxManager.AjaxRequest += (sender, args) => RecreateControlStructure(args.Argument);
}

[/csharp]

In the above replace  [This Is Your Panel] with your Panel control reference since this will be at the field level. Then you are ready to read the properties in the RecreateControlStructure method using a method like:

[csharp]
Dictionary designerData = new JavaScriptSerializer().Deserialize>(argument);
object value;
designerData.TryGetValue(“A Property”, out value);

[/csharp]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *