Setting Event Handlers via JavaScript
RadCheckBoxList 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_
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 RadCheckBoxList.
function Click(sender, args){
alert("RadCheckBoxList's item was clicked");
}
function addHandler(){
var checkboxlist = $find("<%=RadCheckBoxList1.ClientID %>");
checkboxlist.add_itemClicked(Click);
}
Example 2: Adding an anonymous JavaScript click handler to RadCheckBoxList.
function addHandler(){
var checkboxlist = $find("<%=RadCheckBoxList1.ClientID %>");
checkboxlist.add_itemClicked(function (sender, args) { alert("RadCheckBoxList's item was clicked"); });
}
Example 3: Removing the JavaScript click handler of a RadCheckBoxList.
function Click(sender, args){
// code
}
function removeEvents()
{
var checkboxlist = $find("<%= RadCheckBoxList1.ClientID %>");
checkboxlist.remove_itemClicked(Click);
}
Table 1: Available add/remove methods for handling client-side events.
Name | Description |
---|---|
add_selectedIndexChanging | The name of the JavaScript function called when the selected index is to be changed. |
remove_selectedIndexChanging | Removes a handler for the selectedIndexChanging event. |
add_selectedIndexChanged | The name of the JavaScript function called when the selected index is changed. |
remove_selectedIndexChanged | Removes a handler for the selectedIndexChanged event. |
add_itemCheckedChanging | The name of the JavaScript function called when the checked state is to be changed. |
remove_itemCheckedChanging | Removes a handler for the itemCheckedChanging event. |
add_itemCheckedChanged | The name of the JavaScript function called when the checked state is changed. |
remove_itemCheckedChanged | Removes a handler for the itemCheckedChanged event. |
add_load | The name of the JavaScript function called when the control loads. |
remove_load | Removes a handler for the clientLoad event. |
add_itemClicking | The name of the JavaScript function called when the item is clicked, but before itemClicked event. |
remove_itemClicking | Removes a handler for the itemClicking event. |
add_itemClicked | The name of the JavaScript function called when the item is clicked. |
remove_itemClicked | Removes a handler for the itemClicked event. |
add_itemLoad | The name of the JavaScript function called when an item is loaded. |
remove_itemLoad | Removes a handler for the itemLoad event. |
add_itemMouseOver | The name of the JavaScript function called when the mouse cursor moves over an item. |
remove_itemMouseOver | Removes a handler for the itemMouseOver event. |
add_itemMouseOut | The name of the JavaScript function called when the mouse cursor moves out of an item. |
remove_itemMouseOut | Removes a handler for the itemMouseOut event. |