Events Overview
RadSwitch exposes several client-side events that allow easy and flexible use in a wide range of application scenarios:
-
OnClientLoad (load) - raised when the control is initialized.
-
OnClientClicking (clicking) - raised when the user clicks the switch. The event can be canceled.
-
OnClientClicked (clicked) - raised when the switch is clicked. The event is subsequent to the OnClientCheckedChanged event.
-
OnClientCheckedChanging (checkedChanging) - raised after the user clicks the switch and before the checked state is changed. The event can be canceled and it is subsequent to the OnClientCheckedChanged event.
-
OnClientCheckedChanged (checkedChanged) - raised when the checked state of the switch is changed. The event is subsequent to the OnClientCheckedChanging event.
-
OnClientMouseOver (mouseOver) - raised when the mouse hovers over the control.
-
OnClientMouseOut (mouseOut) - raised when the mouse leaves the control.
To handle the desired event, the user must set the respective property to the name of the JavaScript function handling the event or to an anonymous JavaScript function. Here is an example:
Example 1: Passing a named (non-anonymous) JavaScript function.
<script type="text/javascript">
function Click(sender, args) {
alert("RadSwitch was clicked.");
}
</script>
<telerik:RadLabel ID="Label1" runat="server" AssociatedControlID="RadSwitch1" Text="Check here"></telerik:RadLabel>
<telerik:RadSwitch ID="RadSwitch1" runat="server" OnClientClicked="Click">
</telerik:RadSwitch>
RadSwitch1.OnClientClicked = "Click"; //passing the name of the JS function
Example 2: Passing an anonymous JavaScript function.
<script type="text/javascript">
function Click(button, args, arg1, arg2)
{
alert("arg1:" + arg1 + " arg2:" + arg2);
}
</script>
<telerik:RadLabel ID="Label1" runat="server" AssociatedControlID="RadSwitch1" Text="Check here"></telerik:RadLabel>
<telerik:RadSwitch ID="RadSwitch1" runat="server" OnClientClicked="function(sender,args){Click(sender, args, 'Value1', 'Value2');}">
</telerik:RadSwitch>
RadSwitch1.OnClientClicked = "function(sender,args){Click(sender, args, 'Value1', 'Value2');}"; //passing an anonymous JS function