ASP.NET Button Click on enter keypress with Javascript and Telerik radcombobox

by pencilvac 4/24/2012 5:18:00 AM

In most modern web browsers if you have focus in a text box and press the enter key it will submit your form for you. I came across a situation where I wanted my aspx page to postback after a user makes a selection in a telerik radcombobox and then presses the enter key. Normally this does not happen automatically like a regular text box so I need a solution:

SOLUTION: In my radcombobox I used the client side event OnClientKeyPressing:

<telerik:RadComboBox OnClientKeyPressing="CheckPressEnterKey" ID="rcbCounterParties"  runat="server"></telerik:RadComboBox>

This client side event is wired up to the javascript function specified which accepts two arguments sender and args, as is seen below:You can access which key the user pressed in the args argument. The enter key has a keyCode of 13 so with a simple if statement we can test the key, if it is indeed the enter key then we can manually click the button we want. Its that easy.

                function CheckPressEnterKey(sender, args) {

                    if (args._domEvent.keyCode == 13) {
                        document.getElementById('<%=btnLoad.ClientID  %>').click();

Note: You will obviously need to put the javascript function within a telerik radcodeblock in order access the buttons client ID as shown.


.NET | ASP.NET Enterprise Library | JavaScript | Telerik

Powered by BlogEngine.NET
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail


<<  October 2018  >>

View posts in large calendar

Recent comments



The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2018

Sign in