can't click on the button by using enter key

3 posts, 0 answers
  1. TelerikUser
    TelerikUser avatar
    8 posts
    Member since:
    May 2008

    Posted 24 Sep 2009 Link to this post

    I'm using a radformdecorator for a simple login form and for some reason I can't use the Enter key to click on the button and login. Every time I have to use the mouse but many people for convenience use the "enter" button.
    How can I fix it?
    Thank you!
  2. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 28 Sep 2009 Link to this post

    Hi Florin,

    To use Enter key to click as a button, the button should be set as default button of the form.

    This can be done in the code behind for example:
                Button button = //find the button      
                form1.DefaultButton = button.UniqueID; 
    If you have ajaxified your page you should also use the following code:
    Code behind:
    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "scr", String.Format("defaultButton='{0}'", button.ClientID), true); 
    Javascript:
               var defaultButton; 
               function pageLoad() { 
                   
                   if (defaultButton) { 
                        
                       document.forms[0].onkeypress = function(e) { 
                           e = e || window.event; 
                           WebForm_FireDefaultButton(e, defaultButton); 
                       } 
                   } 
               } 

    I hope this will help you.

    All the best,
    Mira
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. TelerikUser
    TelerikUser avatar
    8 posts
    Member since:
    May 2008

    Posted 01 Oct 2009 Link to this post

    The code was ajaxified so the last two blocks of code worked for me. Thank you very much!
Back to Top