Add new Button to RibbonBar in RibbonBar's ButtonClick event handler

3 posts, 0 answers
  1. JP
    JP avatar
    120 posts
    Member since:
    Aug 2011

    Posted 30 Nov 2011 Link to this post

    Hi,

    I want to add new commands to the RibbonBar inside the RibbonBar's ButtonClick event handler. Unfortunately, this doesn't seem to work as they are server-side added, but aren't visible on the client.

    How I can I achieve this?

    Thanks!

    Edit: The ribbon bar is used in an AjaxManager:
    AjaxSetting ajaxSetting1 = new AjaxSetting(m_ribbonBar.ID);
    ajaxSetting1.UpdatedControls.Add(new AjaxUpdatedControl(m_contentPanel.ID, loadingPanel.ID) { UpdatePanelHeight = new Unit("100%") });
    RadAjaxManager1.AjaxSettings.Add(ajaxSetting1);

    In the ButtonClick event (in the same case where it is necessary that the ribbon bar changes), the m_contentPanel (it is just a div) is cleared and another control is added to the content panel.
    When I try to add commands to the RibbonBar, the LoadingPanel also never disappears in the m_contentPanel. If I just add the new control without changed the RibbonBar, the LoadingPanel disappears and the control is displayed correctly.
  2. JP
    JP avatar
    120 posts
    Member since:
    Aug 2011

    Posted 01 Dec 2011 Link to this post

    For testing, I removed the AjaxSettings and tried again. In this case, I get the following error message when I try to add new groups/buttons to the RibbonBar:

    [NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.]
       Telerik.Web.UI.RibbonBarClickableItem.get_ImageRenderingMode() +148
       Telerik.Web.UI.RibbonBarButton.GetCssClass() +52
       Telerik.Web.UI.RibbonBarClickableItem.AddAttributesToRender(HtmlTextWriter writer) +126
       System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +20
       Telerik.Web.UI.RibbonBarClickableItem.RenderBeginTag(HtmlTextWriter writer) +50
       System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +20
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
       Telerik.Web.UI.RibbonBarGroup.RenderContents(HtmlTextWriter writer) +232
       System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +32
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
       Telerik.Web.UI.RadRibbonBar.RenderTabsContent(HtmlTextWriter writer) +383
       Telerik.Web.UI.RadRibbonBar.RenderContents(HtmlTextWriter writer) +301
       System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +32
       Telerik.Web.UI.RadWebControl.Render(HtmlTextWriter writer) +91
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
       System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) +10
       System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +32
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
       System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +173
       System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +31
       System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +53
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
       System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
       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) +100
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
       Telerik.Web.UI.RadAjaxControl.RenderPageInAjaxMode(HtmlTextWriter writer, Control page) +697
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
       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) +100
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060

    If I don't add new groups/buttons to the ribbon bar, everything works fine.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 02 Dec 2011 Link to this post

    Hello Jp,

    Thank you for contacting us.
    I'm sorry to tell you that the RadRibbonBar doesn't support this kind of behaviour. The RibbonBars groups and items are not stored in the ViewState, so every change made in the code behind will get lost after postback. This is a designer's decision, as the developers decided that the amount of ViewState required to store all the items of a RibbonBar was too big and would slow down performance.

    To implement the behaviour you could store the changes you are making to the RibbonBar, and recreate them upon each postback. Also, you must do these changes in the Page_Load event, as the ButtonClick event is too late in the lifecycle of the RibbonBar. If there are more clients that require adding ViewState tracking to RadRibbonBar groups we will consider implementing it for future releases.

    Regards,
    Bozhidar
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top