Hi,
I have a Page Controller design pattern, so I have a base Page class that defines and dumps out a RadAjaxManager control. The (edited) base class is:
| using System; |
| using System.Collections.Generic; |
| using System.Linq; |
| using System.Text; |
| using System.Web; |
| using System.Xml; |
| using xxx.yyy.ASPNET.Security; |
| using xxx.yyy.Client; |
| using xxx.yyy.Client.Security; |
| using xxx.yyy.Core; |
| using Telerik.Web.UI; |
| namespace xxx.yyy.ASPNET |
| { |
| public class AuthenticatedyyyPage : yyyPageBase |
| { |
| private RadAjaxManager _radAjaxManager=null; |
| #region ~ Properties ~ |
| public RadAjaxManager AjaxManager |
| { |
| get { return _radAjaxManager; } |
| } |
| #endregion |
| protected override void OnLoad(EventArgs e) |
| { |
| // set up global AJAX Manager |
| _radAjaxManager = BuildRadAjaxManager(); |
| Form.Controls.Add(_radAjaxManager); |
| if (!ClientScript.IsClientScriptBlockRegistered(_radAjaxManager.ClientID)) |
| { |
| ClientScript.RegisterClientScriptBlock(_radAjaxManager.GetType(), _radAjaxManager.ClientID,GenerateJavascript(),true); |
| } |
| base.OnLoad(e); |
| } |
| protected virtual RadAjaxManager BuildRadAjaxManager() |
| { |
| RadAjaxManager radAjaxManager = new RadAjaxManager(); |
| radAjaxManager.ID = "radAjaxManager"; |
| return radAjaxManager; |
| } |
| private string GenerateJavascript() |
| { |
| StringBuilder sb = new StringBuilder(); |
| sb.Append("\n\nfunction migGetRadAjaxManager() {\n"); |
| sb.Append("\tvar ajaxManager=$find(\"" + _radAjaxManager.ClientID + "\");\n"); |
| sb.Append("\treturn ajaxManager;\n"); |
| sb.Append("}\n\n"); |
| return sb.ToString(); |
| } |
| } |
| } |
(The RadAjaxManager is added into the Form and appears in the rendered HTML)
In the derived page, I want to add an AjaxSetting programmatically (as per http://www.telerik.com/help/aspnet-ajax/ajxaddajaxsettingsprogrammatically.html) in the Page_Load():
| protected void Page_Load(object sender, EventArgs e) |
| { |
| AjaxManager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(AjaxManager_AjaxRequest); |
| AjaxManager.AjaxSettings.AddAjaxSetting(btnCancel0, pnlScriptInjector); |
| } |
But this results in the exception:
Object reference not set to an instance of an object.
| AjaxManager.AjaxSettings.AddAjaxSetting(btnCancel0, pnlScriptInjector); |
| at Telerik.Web.UI.AjaxSettingsCollection.AddAjaxSetting(Control ajaxifiedControl, Control updatedControl) |
| at xxx.yyy.ASPNET.Presentation.Secure.Admin.ImportWindowsUsers.Page_Load(Object sender, EventArgs e) in c:\dev2008\yyy2\yyy_WEB\secure\admin\ImportWindowsUsers.aspx.cs:line 128 |
| at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) |
| at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) |
| at System.Web.UI.Control.OnLoad(EventArgs e) |
| at xxx.yyy.ASPNET.yyyBase.OnLoad(EventArgs e) in C:\dev2008\yyy2\xxx.yyy.ASPNET\yyyPageBase.cs:line 45 |
| at xxx.yyy.ASPNET.Authenticatedyyy.OnLoad(EventArgs e) in C:\dev2008\yyy\xxx.yyy.ASPNET\AuthenticatedyyyPage.cs:line 138 |
| at System.Web.UI.Control.LoadRecursive() |
| at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) |
Inspecting the variables in the debugger and I can't see anything that is null.
Could you please tell me why is this happening? Am I using it right?