New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

OnClientClicking

The clicking event occurs when the RadToggleButton control is clicked, immediately after the mouse button is released. The event is fired after the client-side validation occurs, and can be canceled.

The event handler receives two parameters:

  1. The instance of the clicked RadToggleButton control.

  2. An eventArgs parameter of type Telerik.Web.UI.ButtonCancelEventArgs, containing the following properties and methods:

    • get_cancel() - returns a bool value that indicates whether the event was canceled. True means the event is canceled.

    • set_cancel(shouldCancel) - sets a bool value that indicates whether the event will be canceled. Setting true means the event will be canceled.

    • get_commandName() - returns the value assigned to the RadToggleButton's CommandName property.

    • get_commandArgument() - returns the value assigned to the RadToggleButton's CommandArgument property.

This event is handy in scenarios when the user wants to cancel the page submission, or prevent execution of the other client-side events based on a certain condition. One such scenario is confirming the submission of the page to the server. We ask the user if she wants to submit the page, and if a negative answer is received, we cancel the clicking event. Here is the code:

Example 1: Handling OnClientClicking event in RadToggleButton.

<script type="text/javascript">
    function Clicking(sender, args)
    {
        args.set_cancel(!window.confirm("Are you sure?"));
    }
</script>
<telerik:RadToggleButton ID="RadToggleButton1" runat="server" OnClientClicking="Clicking" OnClick="RadToggleButton1_Click">
    <ToggleStates>
        <telerik:ButtonToggleState Text="State 1" />
        <telerik:ButtonToggleState Text="State 2" />
    </ToggleStates>
</telerik:RadToggleButton>
protected void RadToggleButton1_Click(object sender, System.EventArgs e)
{
    RadToggleButton1.Text = "RadToggleButton was clicked at: " + DateTime.Now.ToString();
}
Protected Sub RadToggleButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    RadToggleButton1.Text = "RadToggleButton was clicked at: " + DateTime.Now.ToString
End Sub

See Also

In this article