OnClientClicking with click()

3 posts, 0 answers
  1. Richard
    Richard avatar
    28 posts
    Member since:
    Jun 2010

    Posted 18 Jul 2011 Link to this post

    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. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 20 Jul 2011 Link to this post

    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!

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Richard
    Richard avatar
    28 posts
    Member since:
    Jun 2010

    Posted 20 Jul 2011 Link to this post

    Hi Slav,

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

    Thanks!
    Richard
Back to Top