Firing the Click Event using jQuery

6 posts, 2 answers
  1. Sébastien
    Sébastien avatar
    60 posts
    Member since:
    Aug 2008

    Posted 21 Feb 2011 Link to this post

    Dear Telerik Team,

    I am actually migrating the asp:button to telerik:radbutton and some logic doesn't work as expected.
    For example, It was easy to use things like that to click a button using jQuery : 

    function keyboardActions(event) {
        if (event.keyCode == 13) {
     
            eval($("#<%=btnSearch.ClientID %>").trigger('click')); // Doesn't work with RadButton Q3.2010
            return false;
        }
        //  other keypressed other actions ?
    }
     
    // If the client press ENTER, the Search button is clicked.
    $(document).ready(function () {
        if ($.browser.mozilla) {
            $("#<%=txtName.ClientID %>").keypress(keyboardActions);
            $("#<%=txtCode.ClientID %>").keypress(keyboardActions);
         } else {
            $("#<%=txtName.ClientID %>").keydown(keyboardActions);
            $("#<%=txtCode.ClientID %>").keydown(keyboardActions);
        }
    });

    How may I do the same logic using RadButton ?

    Cheers,

    S.F.
  2. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 21 Feb 2011 Link to this post

    Hello Sébastien,

    The RadButton has a click() client-side method, that simulates clicking on the button. You should modify the keyboardActions in the following way:
    function keyboardActions(event) {
        if (event.keyCode == 13) {
      
            $find("#<%=btnSearch.ClientID %>").click();
        }
        //  other keypressed other actions ?
    }


    Best wishes,
    Pero
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sébastien
    Sébastien avatar
    60 posts
    Member since:
    Aug 2008

    Posted 22 Feb 2011 Link to this post

    Thank you for your answer,

    Nevertheless, $btnSearch is always null with IE6. It works well with the other web-browsers.
    Any idea why ?
    Please note that the Script block surrounding this function is embedded in a RadCodeBlock.

    function keyboardActions(event) {
        if (event.keyCode == 13) {
      
            var $btnSearch= $find("#<%=btnSearch.ClientID %>");
      
            if ($btnSearch != null) {
                $btnSearch.click();
                return false;
            }
      
        }
    }


    Cheers,

    S.F.
  5. Answer
    Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 22 Feb 2011 Link to this post

    Hello Sebastien,

    The $find method doesn't require you to include the # sign before the control's id. Remove that and see if it works.
  6. Answer
    Pero
    Admin
    Pero avatar
    1156 posts

    Posted 22 Feb 2011 Link to this post

    Hi Sébastien,

    I apologize for giving you incorrect code. The $find shortcut expects the ID of the component to find, and the ID should not start with "#". I simply copied your keyboardActions method and modified only a couple of things, but forgot to remove the "#" character.

    Cori, thank you for noticing this!

    Best wishes,
    Pero
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  7. Sébastien
    Sébastien avatar
    60 posts
    Member since:
    Aug 2008

    Posted 22 Feb 2011 Link to this post

    Thank you both for your answer, it works perfectly now.
    It was working with the other browsers because that's their default behavior.

    S.F.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017