This is a migrated thread and some comments may be shown as answers.

Remove all clicked event handler

4 Answers 382 Views
Button
This is a migrated thread and some comments may be shown as answers.
Jocelyn
Top achievements
Rank 1
Jocelyn asked on 04 Feb 2013, 04:37 PM
Hi!

I just wanted to know how I can remove all OnClientClicked event handler in javacsript client side.

I know there is a "remove_clicked()" but I must pass the function's name, but I don't know the name, so I want to remove all handler on the Clicked event. Is that possible?

Thanks!

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Feb 2013, 07:21 AM
Hi Jocelyn

I am not quite sure about your scenario.Whats the use of a RadButton enabled and having its event OnClientClicked not to fire.
Better try disabling the RadButton
aspx:
<telerik:RadButton ID="RadButton1" runat="server" Text="Rbutton" OnClientLoad="OnClientLoad">
</telerik:RadButton>
JS:
<script type="text/javascript">
function OnClientLoad(sender, args)
    {
       sender.set_enabled(false);
    }
</script>

Thanks,
Princy.
0
Jocelyn
Top achievements
Rank 1
answered on 06 Feb 2013, 01:30 PM
Hi,

this is because I want to set the event client side using "add_clicked()" function. But I want to remove all other handler already set for this event on my button.

Example:

Button1 call function1 and function2 OnClientClicked.

I want to set Button1 OnClientClicked to function3, but I don't want function1 and function2 to be called, so I must remove them.

When I use "add_clicked(function3)" it will call function1, function2 and function3 when I click on the button. That's why I am asking how I can remove all Handlers on this event (Client side) before doing "add_clicked(function3)".

Thanks.
0
Danail Vasilev
Telerik team
answered on 07 Feb 2013, 11:25 AM
Hello Jocelyn,

You can store the names of the dynamically added JavaScript functions (which are to be executed, when OnClientClicked event is triggered) in a custom child object (located in the parent client-side object of the RadButton). Therefore before adding new function to the OnClientClicked event handler, you can remove the previous functions from the stack (you have already stored their names so you can call remove_clicked() method for example). I have created an example and attached it in the archive. You can also watch a short video with the example here.

Regards,
Danail Vasilev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jocelyn
Top achievements
Rank 1
answered on 13 Feb 2013, 01:44 PM
Hi Danail,

this is a good solution, but only if I add my handler on client side. In my case, I can set the OnClientClicked server side.

I found another solution which works for me:

myButton.get_events()._list.clicked = null;
myButton.add_clicked(myFunction);

Thanks for your help!
Tags
Button
Asked by
Jocelyn
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jocelyn
Top achievements
Rank 1
Danail Vasilev
Telerik team
Share this question
or