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

OnClientClicking with click()

2 Answers 128 Views
Button
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 18 Jul 2011, 07:46 PM
Hello,

I have a RadButton on my page which has an OnClientClicking function tied to it.  If I click the button with my mouse, this code is executed as expected.  However, at some points in my page I need to programmatically call the click event.  When I do this, the OnClientClicking is not being called.  OnClientClicked is fired, but I was hoping that the clicking event would be as well.  Is this the intended behavior of the RadButton, or is there something else other than 'click' that I need to call to get this event to fire?  Or is there a way to cancel an event in the 'onclientclicked' function so I can just use that and not the clicking event?  Below is a sample of what I'm talking about (not my exact code but hopefully should give you an idea of what is occuring). 

Thanks!
Richard

// button definition
<telerik:RadButton onclientclicking='Clicking' runat='server' text='Test' id="myButton" />

// javascript
function Clicking(sender, args)
{
   if (!confirm('Ok to continue this action?'))
       args.set_cancel(true);
}

// this function programically causes a click
function ProgramClick()
{
   var btn = $find('myButton');
   btn.click(); // the Clicking event will not be fired.
}

2 Answers, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 20 Jul 2011, 12:44 PM
Hi Richard,

Truly, when click event of RadButton is called programmatically via the .click() method, the OnClientClicking event is not fired, this is the expected behavior. Nonetheless you can easily accomplish your scenario without this event. My suggestion is to insert a confirm dialog check before the client-side click takes place as the example below demonstrates:
function ProgramClick() {
    var btn = $find("<%=myButton.ClientID %>");
    if (confirm('Ok to continue this action?')) {
        btn.click(); // the Clicking event will not be fired.
    }
}

I hope the provided information helps you with your problem.

Kind regards,
Slav
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Richard
Top achievements
Rank 1
answered on 20 Jul 2011, 01:41 PM
Hi Slav,

Thanks for your reply, I'll change my code as you suggested.

Thanks!
Richard
Tags
Button
Asked by
Richard
Top achievements
Rank 1
Answers by
Slav
Telerik team
Richard
Top achievements
Rank 1
Share this question
or