ToolBar

Controls

Rate this demo

Thank you for your post!
Submit a support ticket
If you have an active license or trial, you have access to dedicated support from Telerik’s developers. Response time is 24h for active licenses and 72h for trials, Mon-Fri.
Post in the forums
If you don’t have access to support or would like to help other people by sharing your problem, reach out to our active community in the forums.

ToolBar - Client-side API



Example Configuration

RadToolBar provides a flexible client-side API - you can easily interact with the toolbar in the browser using the toolbar client-side object.

  1. Getting the RadToolBar client-side object: RadToolBar creates a client-side object with the ClientID of the toolbar. You can obtain the reference using the following javascript code:
    var toolBar = $find("<%=RadToolBar1.ClientID%>");
    
  2. Once you get the client-side object of RadToolBar, you can use the findItemByText method to get the instance of a particular item. Example:
    var toolBar = $find("<%= RadToolBar1.ClientID %>");
    var text = $get("<%= TextBox1.ClientID %>").value;
    var item = toolBar.findItemByText(text);
    		
  3. When you get the instance of a particular item, you can call the disable() / enable() / etc. methods.
    function toggleButton()
    {
    	var toolBar = $find("<%= RadToolBar1.ClientID %>");
    	var text = $get("<%= TextBox1.ClientID %>").value;
    	var item = toolBar.findItemByText(text);
    
    	if (!item)
    	{
    		alert("There is no item with text \"" + text + "\"");
    		return false;
    	}
    	
    	if (!Telerik.Web.UI.RadToolBarButton.isInstanceOfType(item))
    	{
    		alert("The item with the specified text is not a button.\nOnly buttons can be checked/unchecked");
    		return false;
    	}
    
    	if (Telerik.Web.UI.IRadToolBarDropDownItem.isInstanceOfType(item.get_parent()))
    	{
    		item.get_parent().showDropDown();
    		item.toggle();
    	}
    
    	return false;
    }
    
C# VB
Show code in new window Demo isolation steps
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.Web.Examples.ToolBar.ClientSide.ClientSideAPI.DefaultCS" %>

<%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>ASP.NET ToolBar Demo - Client-side API</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="true" />
    <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />
     <telerik:RadToolBar ID="RadToolBar1" runat="server" EnableRoundedCorners="true" EnableShadows="true">
     </telerik:RadToolBar>
     <br />
     <br />
     <qsf:ConfiguratorPanel runat="server" ID="ConfigurationPanel1">
          <div style="float: left; width: 380px; padding: 20px 0 0 10px;">
               <asp:Label runat="server" AssociatedControlID="TextBox1" Style="display: none">Toggle button</asp:Label>
               <asp:TextBox runat="server" ID="TextBox1" Text="Bold" Style="border: 1px solid #76C0E0; height: 18px; padding: 2px 2px"></asp:TextBox>
               <asp:Button runat="server" ID="btnToggleButton" OnClientClick="return toggleButton();" Text="Toggle button" Style="vertical-align: top"></asp:Button>
          </div>
          <div style="float: left; width: 200px;">
               <asp:Label runat="server" AssociatedControlID="position">Image position</asp:Label>

               <asp:RadioButtonList runat="server" ID="position" Style="float: left;" RepeatColumns="2">
                    <asp:ListItem Text="Left" Value="Left" Selected="true"></asp:ListItem>
                    <asp:ListItem Text="Right" Value="Right"></asp:ListItem>
                    <asp:ListItem Text="Above Text" Value="AboveText"></asp:ListItem>
                    <asp:ListItem Text="Below Text" Value="BelowText"></asp:ListItem>
               </asp:RadioButtonList>
          </div>
     </qsf:ConfiguratorPanel>
     <script type="text/javascript">
          var $ = $telerik.$;

          /* <![CDATA[ */
          function pageLoad() {
               setHandlersForImagePosition();
          }


          function toggleButton() {
               var toolBar = $find("<%= RadToolBar1.ClientID %>");
               var text = $get("<%= TextBox1.ClientID %>").value;
               var item = toolBar.findItemByText(text);

               if (!item) {
                    alert("There is no item with text \"" + text + "\"");
                    return false;
               }

               if (!Telerik.Web.UI.RadToolBarButton.isInstanceOfType(item)) {
                    alert("The item with the specified text is not a button.\nOnly buttons can be checked/unchecked.");
                    return false;
               }

               if (!item.get_checkOnClick()) {
                    alert(String.format("Button '{0}' is not checkable. Its checked state cannot be changed.", item.get_text()));
                    return false;
               }

               if (Telerik.Web.UI.IRadToolBarDropDownItem.isInstanceOfType(item.get_parent())) {
                    var hideDropDown = function () {
                         item.get_parent().hideDropDown();
                    };

                    var toggle = function () {
                         item.toggle();
                         window.setTimeout(hideDropDown, 400);
                    };

                    var showDropDown = function () {
                         item.get_parent().showDropDown();
                         window.setTimeout(toggle, 400);
                    };

                    window.setTimeout(showDropDown, 300);
               }
               else {
                    item.toggle();
               }

               return false;
          }

          function setHandlersForImagePosition() {
               var inputs = $(".cfgContent input[type='radio']");

               $(inputs).on("change", function () {
                    var selectedPosition = extractPositionFromText($(this).val());
                    
                    setImagePosition(selectedPosition);
               })

          }

          function setImagePosition(selectedPosition) {
               var toolBar = $find("<%=RadToolBar1.ClientID %>");
               var items = toolBar.get_items();
               for (var i = 0; i < items.get_count() ; i++) {
                    items.getItem(i).set_imagePosition(selectedPosition);
               }
               return false;
          }

          function extractPositionFromText(positionAsText) {
               switch (positionAsText) {
                    case "Left":
                         return Telerik.Web.UI.ToolBarImagePosition.Left;
                    case "Right":
                         return Telerik.Web.UI.ToolBarImagePosition.Right;
                    case "AboveText":
                         return Telerik.Web.UI.ToolBarImagePosition.AboveText;
                    case "BelowText":
                         return Telerik.Web.UI.ToolBarImagePosition.BelowText;
               }
          }
          /* ]]> */
     </script>
    </form>
</body>
</html>
Telerik UI for ASP.NET AJAX Q3'14 Release is here