public class TelerikAjaxifiedWebPart : WebPartInstead of Deriving from "WebPart" you can now derive from your custom Class and be sure that the RadAjaxManager is there and useable.
{
RadAjaxManager ajaxManager;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
SetUpAjaxManagerOnPage();
EnsureChildControls();
}
protected void SetUpAjaxManagerOnPage()
{
RadAjaxManager currentAjaxManager = RadAjaxManager.GetCurrent(Page);
if (currentAjaxManager == null)
{
Page.Form.Controls.AddAt(0, AjaxManager);
Page.Items.Add(typeof(RadAjaxManager), AjaxManager);
}
}
protected virtual RadAjaxManager AjaxManager
{
get
{
if (ajaxManager == null)
{
ajaxManager = RadAjaxManager.GetCurrent(Page);
if (ajaxManager == null)
{
ajaxManager = new RadAjaxManager() { ID = "RadAjaxManager1" };
}
}
return ajaxManager;
}
}
}
Now you simply have to add
RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
if (manager != null)
manager.AjaxSettings.AddAjaxSetting(RadGrid1, RadGrid1, RadAjaxLoadingPanel1);
in the Page_Load Method of your <UserControl>.cs file. (The if-Condition just to be sure, usually there shouldn´t be null). You have to add all the controls you want to ajaxify in code (because the markup doesn´t know about the AjaxManager-Control). In the Markup of your userControl you simply have to add your AjaxLoadingPanel you want to use for that control as well as your Controls (like the RadGrid in my example).
As you are using ONE RadAjaxManager for the whole Web-Page, you should not use the RadAjaxManager.DefaultLoadingPanel-Property, instead of that use the Overload of the AddAjaxSetting-Method as I did, which is setting the control firing the AjaxRequest, the one which is getting updated and the LoadingPanel that is used. So you can be sure that the right AjaxLoadingPanel is shown during the AjaxRequest.
Note:
I recommend using the same version of the Telerik-Dll in all of your WebParts (at least all Webparts situated on the same site). I encountered troubles with non-working Javascripts, when they are mixed.
Keine Kommentare:
Kommentar veröffentlichen