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

RadToolBar get_checked() always return "true"

2 Answers 103 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 28 Nov 2014, 04:57 PM
I've implemented a grid with toolbar and a filtering option. I'd like to turn the grids filter on and off when clicking the toolbar button "Filter".

Here is the aspx code and the JS function being called on client click. Most of it is from the forum or the documentation:

            
<telerik:RadToolBar runat="server" ID="RadToolBar1" OnClientButtonClicked="onButtonClicked"
EnableViewState="False" ResolvedRenderMode="Classic" SingleClick="none">
    <Items>
        <telerik:RadToolBarButton Text="Open" ImageUrl="~/Images/reply.gif"
            CommandName="openMail" />
        <telerik:RadToolBarButton IsSeparator="true" />
        <telerik:RadToolBarButton CommandName="showFilter" Text="Filter" CheckOnClick="True">
        </telerik:RadToolBarButton>
    </Items>
</telerik:RadToolBar>


function onButtonClicked(sender, args) {
    var commandName = args.get_item().get_commandName();
    if (commandName == "showFilter") {
        if (tbButton.get_checked()) {
            alert("checked")
            $find('<%=RadGrid1.ClientID %>').get_masterTableView().hideFilterItem();
        } else {
            alert("unchecked")
            $find('<%=RadGrid1.ClientID %>').get_masterTableView().showFilterItem();
        }
    }
}

And I have some code handling other button clicks in VB.

Private Sub RadToolBar1_ButtonClick(sender As Object, e As Telerik.Web.UI.RadToolBarEventArgs) Handles RadToolBar1.ButtonClick
 
    Dim tbBtn As RadToolBarButton = TryCast(e.Item, RadToolBarButton)
 
    Select Case tbBtn.CommandName.ToLower
        Case "openmail"
            OnMessageListSelectionChanged(displayedID, True, False)
    End Select
 
End Sub


My problem is that tbButton.get_checked() always returns true. No matter what the current state is. I assume that there is a second request setting it back... Any ideas how to solve it? Or what exactly the problem is?

Thanks a lot in advance.

2 Answers, 1 is accepted

Sort by
0
Accepted
Schlurk
Top achievements
Rank 2
answered on 01 Dec 2014, 10:02 PM
Hey Martin!

I ran in to this myself once, but managed to solve it pretty easily. I just changed the RadToolBarButton declaration to have one more property, like this:

<telerik:RadToolBarButton CommandName="showFilter" Text="Filter" CheckOnClick="true" AllowSelfUnCheck="true" />

The main difference here is the "AllowSelfUnCheck" which I set to true here. The reasoning is that it seems like CheckOnClick simply allows the user to check the button, but does not allow the user to uncheck the same button. So, every time the user clicks it will always come across as checked because the first time it becomes checked when clicked, and all other times will not remove the state.

Anyways, I found this option by looking in to this documentation article which goes over all of the properties of the different RadToolBar items.

Hope that helps!
0
Martin
Top achievements
Rank 1
answered on 02 Dec 2014, 08:33 AM
Hey Schlurk,

that worked. Thanks a lot!
Tags
ToolBar
Asked by
Martin
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Martin
Top achievements
Rank 1
Share this question
or