Save RibbonBar in Session

2 posts, 0 answers
  1. Thomas
    Thomas avatar
    14 posts
    Member since:
    Mar 2012

    Posted 05 Sep 2012 Link to this post

    Is it possible to save the entire RibbonBar in a Session variable and use it on page load?
    I tried the following but on PostBack it fails.

    if (!Page.IsPostBack)
     TCMenu _rb = new TCMenu();
     _rb.InitRibbonBar(ref trans_RibbonBarMenu); //dynamically adding tabs, groups and buttons - see code below
     Session["Test"] = trans_RibbonBarMenu;
     trans_RibbonBarMenu = (Session["Test"] as RadRibbonBar);

    public void InitRibbonBar(ref RadRibbonBar ribbonBar, string formName, int userLevel)
        CriteriaOperator filter;           
        filter = CriteriaOperator.Parse(String.Format("FormName = '{0}'", formName));
        XPCollection _xpoObjects = new XPCollection(DbUtils.GetDefaultSession, typeof(XPOMenuSettings), filter, null);
        SortProperty TabSortOrder = new SortProperty("TabSortOrder", DevExpress.Xpo.DB.SortingDirection.Ascending);
        SortProperty GroupSortOrder = new SortProperty("GroupSortOrder", DevExpress.Xpo.DB.SortingDirection.Ascending);
        SortProperty sortOrder = new SortProperty("SortOrder", DevExpress.Xpo.DB.SortingDirection.Ascending);
        RibbonBarTab rbt;
        RibbonBarGroup rbg;
        foreach (XPOMenuSettings _xpoButton in _xpoObjects)
            bool rbt_found = true;
            bool rbg_found = true;
            rbt = ribbonBar.FindTabByValue(_xpoButton.TabValue);
            if (rbt == null)
                rbt = new RibbonBarTab();
                rbt.ID = _xpoButton.TabId;
                rbt.Text = _xpoButton.TabText;
                rbt.Value = _xpoButton.TabValue;
                rbt_found = false;
            rbg = ribbonBar.FindGroupByValue(_xpoButton.GroupValue);
            if (rbg == null)
                rbg = new RibbonBarGroup();
                rbg.ID = _xpoButton.GroupId;
                rbg.Text = _xpoButton.GroupText;
                rbg.Value = _xpoButton.GroupValue;
                rbg_found = false;
            RibbonBarButton rbb = new RibbonBarButton();
            rbb.Size = (RibbonBarItemSize)_xpoButton.Size;
            rbb.Text = _xpoButton.Text;
            rbb.Value = _xpoButton.Value;
            rbb.ID = _xpoButton.Id;
            rbb.ImageUrl = _xpoButton.ImageUrl;
            rbb.ImageUrlLarge = _xpoButton.ImageUrlLarge;
            rbb.Visible = _xpoButton.Visible && (_xpoButton.UserLevel >= userLevel);
            rbb.Width = 80;
            if (!rbg_found)
            if (!rbt_found)

    Clientside works fine, but as soon as I click a button that calls serverside, I get the following error message:

    Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index

    [ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index]
       System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) +64
       System.ThrowHelper.ThrowArgumentOutOfRangeException() +15
       System.Collections.Generic.List`1.get_Item(Int32 index) +7500084
       Telerik.Web.UI.RadRibbonBar.RaisePostBackEvent(String eventArgument) +272
       Telerik.Web.UI.RadRibbonBar.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +39
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

  2. Bozhidar
    Bozhidar avatar
    1180 posts

    Posted 10 Sep 2012 Link to this post

    Hi Thomas,

    You have to move the logic that creates the RibbonBar in the Page_Init event.
    Kind regards,
    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