Edit this page

OnClientToggleStateChanging

The toggleStateChanging event is subsequent to the clicking event, and occurs before the RadToggleButton state is changed.

The event handler receives two parameters:

  1. The instance of the clicked RadToggleButton control.

  2. An eventArgs parameter of type Telerik.Web.UI.RadButtonCheckedEventArgs, 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 useful in scenarios where the user wants to make sure the ToggleState is changed only if a certain condition is met. Note that, if the button automatically posts back to the server, which is the default behavior, the postback will not be stopped even if the event is canceled.

The following example asks the user to confirm whether they want to change the state of the button.

Example 1: Using OnClientToggleStateChanging event.

<script type="text/javascript">
    function ToggleStateChanging(sender, args) {
        args.set_cancel(!window.confirm("Are you sure you want to change the state of the button?"));
    }
</script>

<telerik:RadToggleButton ID="RadToggleButton1" runat="server"
    OnClientToggleStateChanging="ToggleStateChanging">
    <ToggleStates>
        <telerik:ButtonToggleState Text="State 1" />
        <telerik:ButtonToggleState Text="State 2" />
    </ToggleStates>
</telerik:RadToggleButton>

See Also