Render RadToolbar null exception

6 posts, 2 answers
  1. Jiří
    Jiří avatar
    36 posts
    Member since:
    Mar 2009

    Posted 20 Mar 2009 Link to this post

    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
  2. Jiří
    Jiří avatar
    36 posts
    Member since:
    Mar 2009

    Posted 23 Mar 2009 Link to this post

    This topic should be in "RadControls for ASP.NET" forum, not AJAX!
    I am not able to move it there :-(
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 23 Mar 2009 Link to this post

    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.
  5. Jiří
    Jiří avatar
    36 posts
    Member since:
    Mar 2009

    Posted 23 Mar 2009 Link to this post

    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

  6. Answer
    Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 24 Mar 2009 Link to this post

    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.

     

  7. Jiří
    Jiří avatar
    36 posts
    Member since:
    Mar 2009

    Posted 30 Mar 2009 Link to this post

    Thank you for you answer, this concept works.

    Jirka
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017