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

Render RadToolbar null exception

5 Answers 90 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Jiří
Top achievements
Rank 1
Jiří asked on 20 Mar 2009, 05:15 PM
Hello,

I am trying to put RadToolbar into my own user or server control. When I call radToolbar.Render(writer) method I get an exception "Object reference not set to an instance of an object". Both radToolbar and writer are not null of course.
When I replace radToolbar with a standard Button for example, everything works fine.

The code of custom control Render method is:
    protected override void Render(HtmlTextWriter writer) {  
      RadToolbar MainToolbar = new RadToolbar();  
      RadToolbarButton b = new RadToolbarButton() { ButtonText = "Detail0" };  
      MainToolbar.Controls.Add(b);  
 
      MainToolbar.RenderControl(writer);  
      base.Render(writer);  
    } 

An exception is:
[NullReferenceException: Object reference not set to an instance of an object.]  
   Telerik.WebControls.RadToolbar.Render(HtmlTextWriter writer) +106  
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27  
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99  
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25  
   Sprinx.Crm.ExportDevelop.WebUserControl1.Render(HtmlTextWriter writer) in D:\TFS\Sprinx.CRM\Main\Source\Sprinx.Crm.Export\Sprinx.Crm.ExportDevelop\WebUserControl1.ascx.cs:36  
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27  
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99  
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25  
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134  
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19  
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +163  
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32  
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +51  
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27  
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99  
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40  
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134  
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19  
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29  
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27  
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99  
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25  
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266  
 

Thanks a lot

Jiří Nouza

5 Answers, 1 is accepted

Sort by
0
Jiří
Top achievements
Rank 1
answered on 23 Mar 2009, 03:10 PM
This topic should be in "RadControls for ASP.NET" forum, not AJAX!
I am not able to move it there :-(
0
Accepted
Atanas Korchev
Telerik team
answered on 23 Mar 2009, 03:43 PM
Hello Jiří,

Please use the Items property of the toolbar when adding items as demonstrated in this example. Also make sure the toolbar control is added to a live controls collection before calling the RenderControl method:

  protected override void Render(HtmlTextWriter writer) { 
      RadToolbar MainToolbar = new RadToolbar(); 
      RadToolbarButton b = new RadToolbarButton() { ButtonText = "Detail0" }; 
      MainToolbar.Items.Add(b); 
      this.Controls.Add(MainToolbar);
      MainToolbar.RenderControl(writer);
      this.Controls.Remove(MainToolBar);
      base.Render(writer); 
    }

Sincerely yours,
Albert
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Jiří
Top achievements
Rank 1
answered on 23 Mar 2009, 06:04 PM

Thank you for your quick answer.

The reason for rendering RadToolbar was to provide RadGrid with customized data processing and provide backwards compatibility with current <rad:RadGrid> aspx code definition. And even integrates menu with event handling.

So the desicion was to inherit RadGrid, add a private member RadToolbar which contains standard set of commands and handle events. Let the aspx page be responsible just for columns, not menu.
The problem is when a RadToolbar object is added to a RadGrid.Controls collection, which seems necessary to provide event handling. Is it posible to compose your controls in this way or the only way is to make a new standard WebControl which consist of more rad controls. And has to make explicitly radgrid properties public.

Thank you

0
Accepted
Sebastian
Telerik team
answered on 24 Mar 2009, 02:13 PM

Hello Jiří,

Thank you for the explanation.

One possible solution for your case would be to incorporate the RadToolBar inside the RadGrid's command item in order to take advantage of its event bubbling mechanism. The following integration demo illustrates the approach:

http://demos.telerik.com/aspnet-ajax/toolbar/examples/applicationscenarios/gridcommanditem/defaultcs.aspx?product=toolbar

If you want to inherit the grid control and inject directly the RadToolBar instance as part of it, note that you can instantiate its command item template programmatically as explained in the last paragraph of this help article.

Kind regards,
Sebastian,
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.

0
Jiří
Top achievements
Rank 1
answered on 30 Mar 2009, 08:45 AM
Thank you for you answer, this concept works.

Jirka
Tags
ToolBar
Asked by
Jiří
Top achievements
Rank 1
Answers by
Jiří
Top achievements
Rank 1
Atanas Korchev
Telerik team
Sebastian
Telerik team
Share this question
or