New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Setting Event Handlers via JavaScript

RadSwitch API exposes client-side methods to attach and detach functions to its event. They can be used as an alternative to the server-side properties for handling events.

To handle the desired event, you can use the respective add_(handlerFunction) to attach the desired handler (i.e., add_clicked for the clicked event), where the parameter handlerFunction should be of type function. To remove the handler that has been added previously, the respective remove_(handlerFunction) should be used.

The next three examples show how to add and remove handlers on the client:

Example 1: Adding a named (non-anonymous) JavaScript click handler to RadSwitch.

ASP.NET
<script type="text/javascript">
	function Click(switchObj, args)
	{
		alert("switch was clicked");
	}
	function addHandler()
	{
		var switchObj = $find("<%=RadSwitch1.ClientID %>");
		switchObj.add_clicked(Click);
	}
</script>

Example 2: Adding an anonymous JavaScript click handler to RadSwitch.

ASP.NET
<script type="text/javascript">
	function Click(switchObj, args, arg1)
	{
		alert("switch was clicked. arg1: " + arg1);
	}
	function addHandler()
	{
		var switchObj = $find("<%=RadSwitch1.ClientID %>");
		switchObj.add_clicked(function (switchObj, args) { Click(switchObj, args, "Value1") });
	}
</script>

Example 3: Removing the JavaScript click handler of a RadSwitch.

JavaScript
function removeEvents()
{
    var switchObj = $find("<%= RadSwitch1.ClientID %>");
    switchObj.remove_click(Click);
}

Table 1: Available add/remove methods for handling client-side events.

NameDescription
add_loadThe name of the JavaScript function called when the control loads.
remove_loadRemoves a handler for the load event.
add_clickingThe name of the JavaScript function called when the RadSwitch control is clicked.
remove_clickingRemoves a handler for the clicking event.
add_checkedChangingThe name of the JavaScript function called before the checked state of the switch is changed.
remove_checkedChangingRemoves a handler for the checkedChanging event.
add_checkedChangedThe name of the JavaScript function called when the checked state of the switch is changed.
remove_checkedChangedRemoves a handler for the checkedChanged event.
add_clickedThe name of the JavaScript function called when the RadSwitch control is clicked.
remove_clickedRemoves a handler for the clicked event.
add_mouseOverThe name of the JavaScript function called when the mouse hovers over the control.
remove_mouseOverRemoves a handler for the mouseOver event.
add_mouseOutThe name of the JavaScript function when the mouse leaves the control.
remove_mouseOutRemoves a handler for the mouseOut event.

See Also

In this article
See Also
Not finding the help you need?
Contact Support