RadToolBarSplitButton inside RadGrid not persisted

5 posts, 0 answers
  1. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 18 Jul 2013 Link to this post

    I have a toolbar inside my CommandItem in RadGrid.
    I'm able to correctly bubble events or fire custom events in the ItemCommand event.
    The issue I'm facing is with RadToolBarSplitButton not persisting the button pressed after grid rebind.
    For example one of my SplitButtons in the dropdown removes all filters like that

    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
                Select Case e.CommandName
                    Case "ClearFilters"
                        For Each column As GridColumn In RadGrid1.MasterTableView.Columns
                            column.CurrentFilterFunction = GridKnownFunction.NoFilter
                            column.CurrentFilterValue = String.Empty
                        Next
                        RadGrid1.MasterTableView.FilterExpression = String.Empty
                        RadGrid1.MasterTableView.Rebind()
                End Select
    End Sub

    I've tryed to access the bar and set the defaultindex to persist the choice but that is overridden in the itemcreated event fired again after rebind. Any hint other than persisintg the choice somewhere (session/viewstate/cookie) and reading it in the ItemCreated event? Shouldn't this already be persisted (and restored) by default somewhere in cookie/viewstate/controlstate?. If this doesn't happens in a RadGrid/ItemCommand implementation how could I read the default persistence mechanism in the ItemCreated event without reinventing the wheel with my custom persistance?
    What I tryed (with no success) is this:

            Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
                Select Case e.CommandName
                    Case "ClearFilters"
                        Dim toolbar As RadToolBar = DirectCast(e.CommandSource, RadToolBar)
                        Dim button As RadToolBarSplitButton = DirectCast(toolbar.FindItemByText("Ricerca"), RadToolBarSplitButton)
                        button.EnableDefaultButton = True
                        button.DefaultButtonIndex = 2
     
                        For Each column As GridColumn In RadGrid1.MasterTableView.Columns
                            column.CurrentFilterFunction = GridKnownFunction.NoFilter
                            column.CurrentFilterValue = String.Empty
                        Next
                        RadGrid1.MasterTableView.FilterExpression = String.Empty
                        RadGrid1.MasterTableView.Rebind()
                  End Select
    End Sub

    EDIT: if I bind RebindGridCommandName to the button, instead of my custom command (and in this case rebinding happens the same since the command is for refreshing the grid) this button is persisted without any addittional code handling. With my custom command intercepted in the ItemCommand event this doesn't happen
  2. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 23 Jul 2013 Link to this post

    Hello Massimiliano,

    I am afraid that the selected button is not persisted through postback and you have to do it manually. I prepared a small sample where I demonstrates a possible approach to persist the selected button. Please give it a try and let me know about the result.

    Regards,
    Kostadin
    Telerik
    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 the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 23 Jul 2013 Link to this post

    Thank you Kostadin you were precious. I not only think Telerik controls are the best but support also in this forum is first class!!
    Only downside I think the AJAX suite is a bit too pricey for very small developers. If it was a one-time fee it could even be a no brainer but as a yearly fee to access upgrades it really becomes pricey for very small biz.
  5. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 27 Jul 2013 Link to this post

    Thank you Kostadin I've been able to check your files only today and the solution is what I had in mind for custom persistance of the splitbutton.
    The only thing I was missing was to do it in the PreRender event, that's why my first tests didn't gave appreciable results.
    Very helpful as always!

    BTW Shouldn't this be handled automatically like in any other controls (splitter or tabstrip)? It's just the grid that breaks it and as a standalone control the toolbar handles it automatically?
  6. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 31 Jul 2013 Link to this post

    Hi Massimiliano,

    I am afraid that this could not be handled automatically, because the state of the current chosen item of the RadToolBarSplitButton is not save at the ViewState at that moment. When you call Rebind() method the RadGrid recreate the last saved state of the button from the ViewState which is the initial chosen item. In order to show the last chosen item you have explicitly save the state of the Button into the ViewState.

    Regards,
    Kostadin
    Telerik
    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 the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017