Edit this page

Events Overview

RadButton Client-side events

The RadButton exposes several client-side events which allow easy and flexible use in a wide range of application scenarios:

The event handler method for any of the events can be set on the server and on the client.

Server-side

To handle the desired event, the user must set the respective property to the name of the JavaScript function handling the event or to anonymous JavaScript function. Here is an example:

  • Passing named (non-anonymous) JavaScript function
<script type="text/javascript">
    function Click(sender, args)
    {
        alert("RadButton was clicked.");
    }
</script>
<telerik:RadButton RenderMode="Lightweight" ID="RadButton1" runat="server" OnClientClicked="Click">
</telerik:RadButton>
RadButton1.OnClientClicked = "Click";  //passing the name of the JS function
RadButton1.OnClientClicked = "Click"  'passing the name of the JS function
  • Passing anonymous JavaScript function
<script type="text/javascript">
    function Click(button, args, arg1, arg2)
    {
        alert("arg1:" + arg1 + " arg2:" + arg2);
    }
</script>

<telerik:RadButton RenderMode="Lightweight" ID="RadButton1" runat="server" OnClientClicked="function(sender,args){Click(sender, args, 'Value1', 'Value2');}">
</telerik:RadButton>
RadButton1.OnClientClicked = "function(sender,args){Click(sender, args, 'Value1', 'Value2');}"; //passing the name of the JS function
RadButton1.OnClientClicked = "function(sender,args){Click(sender, args, 'Value1', 'Value2');}"  'passing the name of the JS function

Client-side

To handle the desired event, the user should 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 a handler that has been added previously, the respective remove_(handlerFunction) should be used.

Here is an example showing how to add handler on the client:

  • Adding named (non-anonymous) JavaScript function
<script type="text/javascript">
    function Click(button, args)
    {
        alert("Button was clicked");
    }
    function addHandler()
    {
        var button = $find("<%=RadButton1.ClientID %>");
        button.add_clicked(Click);
    }
</script>
  • Adding anonymous JavaScript function
<script type="text/javascript">
    function Click(button, args, arg1)
    {
        alert("Button was clicked. arg1: " + arg1);
    }
    function addHandler()
    {
        var button = $find("<%=RadButton1.ClientID %>");
        button.add_clicked(function (button, args) { Click(button, args, "Value1") });
    }
</script>