Server side button events and command name

2 posts, 0 answers
  1. Jaymie
    Jaymie avatar
    57 posts
    Member since:
    Jan 2009

    Posted 01 May 2009 Link to this post

    The documentation for the toolbar is shocking...

    I have a toolbar on a page which looks like:

    <telerik:RadToolBar ID="RadToolBar1" runat="server" Skin="Black" Style="width: 100%;"
    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
            <telerik:RadToolBarButton runat="server" Text="Bold" AccessKey="b" ToolTip="Bold (Alt+B)" CommandName="Bold" CheckOnClick="true" AllowSelfUnCheck="true" Group="Bold" /> 
            <telerik:RadToolBarButton runat="server" Text="Underline" AccessKey="u" ToolTip="Underline (Alt+U)" CommandName="Underline" CheckOnClick="true" AllowSelfUnCheck="true" Group="Underline" /> 
            <telerik:RadToolBarButton runat="server" Text="Italic" AccessKey="i" ToolTip="Italic (Alt+I)" CommandName="Italic" CheckOnClick="true" AllowSelfUnCheck="true" Group="Italic" /> 
            <telerik:RadToolBarButton runat="server" Text="Quote" AccessKey="q" ToolTip="Quote (Alt+Q)" CommandName="Quote" CheckOnClick="true" AllowSelfUnCheck="true" Group="Quote" /> 
            <telerik:RadToolBarButton runat="server" Text="Code" AccessKey="c" ToolTip="Code (Alt+C)" CommandName="Code" CheckOnClick="true" AllowSelfUnCheck="true" Group="Code" /> 
            <telerik:RadToolBarButton runat="server" Text="Image" AccessKey="m" ToolTip="Image (Alt+M)" CommandName="Image" CheckOnClick="true" AllowSelfUnCheck="true" Group="Image" /> 
            <telerik:RadToolBarButton runat="server" Text="Link" AccessKey="l" ToolTip="Link (Alt+L)" CommandName="Link" CheckOnClick="true" AllowSelfUnCheck="true" Group="Link" /> 
            <telerik:RadToolBarButton runat="server" Text="Item" AccessKey="t" ToolTip="Item Links (Alt+T)" CommandName="Item" CheckOnClick="true" AllowSelfUnCheck="true" Group="Item" /> 
            <telerik:RadToolBarButton runat="server" IsSeparator="True" /> 
            <telerik:RadToolBarDropDown runat="server" Text="Size"
                    <telerik:RadToolBarButton runat="server" Text="Smallest" /> 
                    <telerik:RadToolBarButton runat="server" Text="Small" /> 
                    <telerik:RadToolBarButton runat="server" Text="Normal" /> 
                    <telerik:RadToolBarButton runat="server" Text="Large" /> 
                    <telerik:RadToolBarButton runat="server" Text="Largest" /> 
            <telerik:RadToolBarDropDown runat="server" Text="Color"
                    <telerik:RadToolBarButton runat="server" Text="Dark Red" /> 
                    <telerik:RadToolBarButton runat="server" Text="Red" /> 
                    <telerik:RadToolBarButton runat="server" Text="Orange" /> 
                    <telerik:RadToolBarButton runat="server" Text="Brown" /> 
                    <telerik:RadToolBarButton runat="server" Text="Yellow" /> 
                    <telerik:RadToolBarButton runat="server" Text="Green" /> 
                    <telerik:RadToolBarButton runat="server" Text="Olive" /> 
                    <telerik:RadToolBarButton runat="server" Text="Cyan" /> 
                    <telerik:RadToolBarButton runat="server" Text="Blue" /> 
                    <telerik:RadToolBarButton runat="server" Text="Dark Blue" /> 
                    <telerik:RadToolBarButton runat="server" Text="Violet" /> 
                    <telerik:RadToolBarButton runat="server" Text="White" /> 
                    <telerik:RadToolBarButton runat="server" Text="Black" />                 

    As you can see, The first few buttons are toggle buttons.
    Now, in my code I have:

        Protected Sub RadToolBar1_ButtonClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadToolBarEventArgs) Handles RadToolBar1.ButtonClick 
            ' Create our Variables 
            Dim sCommand As String = e.Item.Text 
            ' Select Case 
            Select Case sCommand 
                Case "Bold" 
                    ' Output the button text 
                    Body.Text = sCommand 
            End Select 
        End Sub 

    I would like to access other properties, for me the text property isn't enough. I need (or would like) the CommandName and also to check the state of the button, i.e. is it toggled on or off.
    I don't want to have to do this clientside.

    Can this be done?

  2. Peter
    Peter avatar
    6637 posts

    Posted 01 May 2009 Link to this post

    Hi Jaymie,

    Thank you for your feedback. Your point is well taken and we will update the documentation as per your suggestion.

    If you need to access button properties from server side, you have to explicitly cast e.Item to RadToolBarButton type. Here is an example:
    Protected Sub RadToolBar1_ButtonClick(sender As Object, e As Telerik.Web.UI.RadToolBarEventArgs)  
        Literal1.Text = [String].Empty  
        Dim btn As RadToolBarButton = TryCast(e.Item, RadToolBarButton)  
        Literal1.Text += "Command name: " + btn.CommandName.ToString() + "<br/>" 
        Literal1.Text += "Checked: " + btn.Checked.ToString()  
    End Sub 

    All the best,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft R3 2016 release webinar banner
Back to Top