Product Bundles
DevCraft
All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:
Web
Mobile
Document Management
Desktop
Reporting
Testing & Mocking
CMS
UI/UX Tools
Debugging
Free Tools
Support and Learning
Productivity and Design Tools
New to Telerik UI for ASP.NET AJAX? Download free 30-day trial
RadToolBar provides a number of client-side events that would allow you to accomplish even the most complicated tasks.
You can attach to the RadTollBar's events by using either the server-side properties or the client-side API.
<script type="text/javascript"> function onButtonClicked(sender, args) { alert(String.format("Button with text: '{0}' clicked", args.get_item().get_text())); } </script> <telerik:RadToolBar ID="RadToolBar1" runat="server" OnClientButtonClicked="onButtonClicked"> </telerik:RadToolBar>
<script type="text/javascript"> function onClickedHandler1() { alert("First handler called"); } function onClickedHandler2() { alert("Second handler called"); } function pageLoad() { var toolBar = $find("<%=RadToolBar1.ClientID%>"); toolBar.add_buttonClicked(onClickedHandler1); toolBar.add_buttonClicked(onClickedHandler2); } </script>
Another advantage of the client-side API is the possiblity of dynamically detaching certain handlers. You can use the remove_buttonClicked method of the toolbar object.
remove_buttonClicked
<script type="text/javascript"> $find(<%=RadToolBar1.ClientID%>).remove_buttonClicked(onClickedHandler1); </script>
<script type="text/javascript"> function onClientButtonClicking(sender, eventArgs) { eventArgs.set_cancel(true); } </script>
There are several important points about button checking:
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="DefaultVB.aspx.vb" Inherits="ToolBar.Examples.ClientSide.ClientEvents.DefaultVB" %> <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %> <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> <!DOCTYPE html> <html xmlns='http://www.w3.org/1999/xhtml'> <head runat="server"> <title>Telerik ASP.NET Example</title> <link rel="stylesheet" type="text/css" href="styles.css" /> </head> <body> <form id="form1" runat="server"> <telerik:RadScriptManager runat="server" ID="RadScriptManager1" /> <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" /> <script type="text/javascript"> //<![CDATA[ function onClientToolBarLoad(sender, args) { logEvent("OnClientLoad: " + sender.get_id()); } function clientButtonClicking(sender, args) { logEvent("OnClientButtonClicking: " + args.get_item().get_text()); } function clientButtonClicked(sender, args) { logEvent("OnClientButtonClicked: " + args.get_item().get_text()); } function clientDropDownOpening(sender, args) { logEvent("OnClientDropDownOpening: " + args.get_item().get_text()); } function clientDropDownOpened(sender, args) { logEvent("OnClientDropDownOpened: " + args.get_item().get_text()); } function clientDropDownClosing(sender, args) { logEvent("OnClientDropDownClosing: " + args.get_item().get_text()); } function clientDropDownClosed(sender, args) { logEvent("OnClientDropDownClosed: " + args.get_item().get_text()); } function clientContextMenu(sender, args) { logEvent("OnClientContextMenu: " + args.get_item().get_text()); } function clientMouseOver(sender, args) { logEvent("OnClientMouseOver: " + args.get_item().get_text()); } function clientMouseOut(sender, args) { logEvent("OnClientMouseOut: " + args.get_item().get_text()); } function clientCheckedStateChanging(sender, args) { logEvent("OnClientCheckedStateChanging: " + args.get_item().get_text()); } function clientCheckedStateChanged(sender, args) { logEvent("OnClientCheckedStateChanged: " + args.get_item().get_text()); } //]]> </script> <div class="demo-container size-narrow"> <telerik:RadToolBar RenderMode="Lightweight" ID="RadToolBar1" runat="server" EnableRoundedCorners="true" EnableShadows="true" OnClientLoad="onClientToolBarLoad" OnClientButtonClicking="clientButtonClicking" OnClientButtonClicked="clientButtonClicked" OnClientDropDownOpening="clientDropDownOpening" OnClientDropDownOpened="clientDropDownOpened" OnClientDropDownClosing="clientDropDownClosing" OnClientDropDownClosed="clientDropDownClosed" OnClientContextMenu="clientContextMenu" OnClientMouseOver="clientMouseOver" OnClientMouseOut="clientMouseOut" OnClientCheckedStateChanging="clientCheckedStateChanging" OnClientCheckedStateChanged="clientCheckedStateChanged"> <Items> <telerik:RadToolBarButton Text="Select" AllowSelfUnCheck="True" CheckOnClick="True"> </telerik:RadToolBarButton> <telerik:RadToolBarButton Text="Save"> </telerik:RadToolBarButton> <telerik:RadToolBarButton Text="Load"> </telerik:RadToolBarButton> <telerik:RadToolBarDropDown Text="Format"> <Buttons> <telerik:RadToolBarButton Text="Bold" CheckOnClick="true" Group="FormatBold" Checked="true"> </telerik:RadToolBarButton> <telerik:RadToolBarButton Text="Italic" CheckOnClick="true" Group="FormatItalic"> </telerik:RadToolBarButton> <telerik:RadToolBarButton Text="Underline" CheckOnClick="true" Group="FormatUnderline"> </telerik:RadToolBarButton> </Buttons> </telerik:RadToolBarDropDown> <telerik:RadToolBarSplitButton Text="Apply Color (Red)" EnableDefaultButton="false"> <Buttons> <telerik:RadToolBarButton Text="Red" CheckOnClick="true" Group="ApplyColor" Checked="true"> </telerik:RadToolBarButton> <telerik:RadToolBarButton Text="Blue" CheckOnClick="true" Group="ApplyColor"> </telerik:RadToolBarButton> <telerik:RadToolBarButton Text="Yellow" CheckOnClick="true" Group="ApplyColor"> </telerik:RadToolBarButton> </Buttons> </telerik:RadToolBarSplitButton> </Items> </telerik:RadToolBar> <telerik:RadContextMenu id="RadContextMenu1" runat="server"> <Targets> <telerik:ContextMenuControlTarget ControlID="RadToolBar1" /> </Targets> <Items> <telerik:RadMenuItem Text="Edit" Value="E" /> <telerik:RadMenuItem Text="Add" Value="A" /> <telerik:RadMenuItem Text="Delete" Value="D" /> </Items> </telerik:RadContextMenu> </div> <qsf:EventLogConsole runat="server" ID="EventLogConsole1" Height="200px"></qsf:EventLogConsole> <qsf:ConfiguratorPanel runat="server" ID="ConfigurationPanel1" Title="Logged events" Orientation="Vertical" Expanded="true"> <Views> <qsf:View> <asp:CheckBoxList ID="cblLoggedEvents" runat="server" AutoPostBack="true" OnSelectedIndexChanged="cblLoggedEvents_SelectedIndexChanged"> <asp:ListItem Text="OnClientLoad" Selected="true"></asp:ListItem> <asp:ListItem Text="OnClientButtonClicking" Selected="true"></asp:ListItem> <asp:ListItem Text="OnClientButtonClicked" Selected="true"></asp:ListItem> <asp:ListItem Text="OnClientDropDownOpening" Selected="true"></asp:ListItem> <asp:ListItem Text="OnClientDropDownOpened" Selected="true"></asp:ListItem> <asp:ListItem Text="OnClientDropDownClosing" Selected="true"></asp:ListItem> <asp:ListItem Text="OnClientDropDownClosed" Selected="true"></asp:ListItem> <asp:ListItem Text="OnClientContextMenu" Selected="true"></asp:ListItem> <asp:ListItem Text="OnClientMouseOver" Selected="true"></asp:ListItem> <asp:ListItem Text="OnClientMouseOut" Selected="true"></asp:ListItem> <asp:ListItem Text="OnClientCheckedStateChanging" Selected="true"></asp:ListItem> <asp:ListItem Text="OnClientCheckedStateChanged" Selected="true"></asp:ListItem> </asp:CheckBoxList> </qsf:View> </Views> </qsf:ConfiguratorPanel> </form> </body> </html>