This is a migrated thread and some comments may be shown as answers.

Cannot unregister UpdatePanel in Radgrid

2 Answers 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RB
Top achievements
Rank 1
RB asked on 18 Apr 2014, 09:34 PM
I am creating a RadGrid as follows:
protected override void OnInit(EventArgs e)
      {
          this.Controls.Clear();
          this._RadLoadingPanel.ID = "_RadLoadingPanel";
          this._RadLoadingPanel.Transparency = 30;
          this._RadLoadingPanel.Skin = "WebBlue";
          this._RadLoadingPanel.BackgroundPosition = AjaxLoadingPanelBackgroundPosition.Center;
          this.Controls.Add(this._RadLoadingPanel);
 
          this._RadGrid1.Skin = "WebBlue";
          this._RadGrid1.Width = Unit.Percentage(98);
          this._RadGrid1.GridLines = GridLines.None;
 
          this._RadGrid1.AutoGenerateColumns = false;
          this._RadGrid1.AllowSorting = true;
          this._RadGrid1.GridLines = GridLines.None;
          this._RadGrid1.PageSize = 100;
          this._RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
          this._RadGrid1.ShowGroupPanel = true;
          this._RadGrid1.AllowPaging = true;
          this._RadGrid1.AllowSorting = true;         
          this._RadGrid1.EnableLinqExpressions = false;
          this._RadGrid1.MasterTableView.NoMasterRecordsText = string.Format("There are no documents associated with this order / quote / proposal.");
          this._RadGrid1.MasterTableView.Width = Unit.Percentage(100);                 
           
          this._RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
                      
         // Setup Columns          
          GridBoundColumn boundColumn = new GridBoundColumn();
          this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
          boundColumn.DataField = this._DocList.DescriptionColumn.ColumnName;
          boundColumn.HeaderText = "Document Type";
          boundColumn.UniqueName = "DocumentType";
          boundColumn.AllowSorting = true;     
        
          this._UpdatePanel.Unload += new EventHandler(UpdatePanel_Unload);
          this._UpdatePanel.ID = "ajaxPanel";
          this._UpdatePanel.UpdateMode = UpdatePanelUpdateMode.Always;
          this._UpdatePanel.ContentTemplateContainer.Controls.Add(this._RadGrid1);
 
          this.Controls.Add(this._UpdatePanel);
                       
          base.OnInit(e);
        
      }
protected override void OnPreRender(EventArgs e)
      {
          _RadGrid1.MasterTableView.Rebind();
          base.OnPreRender(e);       
          var ajaxManager = RadAjaxManager.GetCurrent(Page);
 
          if (ajaxManager != null)
              ajaxManager.AjaxSettings.AddAjaxSetting(this._UpdatePanel, this._RadGrid1, this._RadLoadingPanel);         
      }

It gives the following error:
Cannot unregister UpdatePanel with ID 'ajaxPanel' since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported.
Parameter name: updatePanel

After reading in forums I added the following:
void UpdatePanel_Unload(object sender, EventArgs e)
     {
         MethodInfo methodInfo = typeof(ScriptManager).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
     .Where(i => i.Name.Equals("System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel")).First();
         methodInfo.Invoke(ScriptManager.GetCurrent(Page),
             new object[] { sender as UpdatePanel });
     }      

This did not resolve it. I even added this.COntrols.clear, but did not work. When I comment out the  boundColumn.DataField = this._DocList.DescriptionColumn.ColumnName; statement, it displays a grid.
Please help me resolve this.

2 Answers, 1 is accepted

Sort by
0
RB
Top achievements
Rank 1
answered on 18 Apr 2014, 09:57 PM
I forgot to mention that this Radgrid is placed inside another Update Panel.
0
Eyup
Telerik team
answered on 23 Apr 2014, 06:38 AM
Hello Ruchi,

Please note that using UpdatePanel simultaneously with RadAjaxManager or RadAjaxPanel( or implementing multiple wrapped UpdatePanel) is not a supported scenario and we highly recommend to avoid such implementation. Please either use just the manager to update your controls replacing the UpdatePanel / RadAjaxPanel with a regular asp:Panel, or use the UpdatePanel / RadAjaxPanel alone to wrap your page:
http://www.telerik.com/help/aspnet-ajax/ajax-controls-in-ajaxpanel-and-ajaxsettings.html


In addition, when creating a RadGrid control programmatically, you should strictly follow the steps provided in this article:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section22

And finally, remove the Controls.Clear() and instead of adding the controls directly to Page.Controls using this.Controls, use an asp:PlaceHolder or Form.Controls.Add.

Hope this helps.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
RB
Top achievements
Rank 1
Answers by
RB
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or