Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

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;
      }
      

Source Code

C# VB.NET
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="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ 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">
        <qsf:HeadTag runat="server" ID="Headtag1" />
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
            <telerik:RadScriptManager ID="ScriptManager" runat="server" />
            
            <qsf:Header runat="server" ID="Header1" NavigationLanguage="C#" />

            <telerik:RadToolBar ID="RadToolBar1" runat="server" EnableRoundedCorners="true" EnableShadows="true" />
            <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:Button runat="server" ID="btnToggleButton" CssClass="button" OnClientClick="return toggleButton();" Text="Toggle button" style="vertical-align: top" />
                </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" onclick="setImagePosition();" />
                        <asp:ListItem Text="Right" Value="Right" onclick="setImagePosition();" />
                        <asp:ListItem Text="Above Text" Value="AboveText" onclick="setImagePosition();" />
                        <asp:ListItem Text="Below Text" Value="BelowText" onclick="setImagePosition();" />
                    </asp:RadioButtonList>
                </div>
            </qsf:ConfiguratorPanel>
            
            <script type="text/javascript">
            /* <![CDATA[ */
            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 setImagePosition()
            {
                var positionRadios = document.getElementsByName("position");
                var selectedPosition = Telerik.Web.UI.ToolBarImagePosition.Left;
                for (var i=0; i<positionRadios.length; i++)
                {
                    if (positionRadios[i].checked)
                    {
                        selectedPosition = extractPositionFromText(positionRadios[i].value);
                        break;
                    }
                }

                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>

            <qsf:Footer runat="server" ID="Footer1" />
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451