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

RadNumericTextBox - Enter

3 Answers 208 Views
Input
This is a migrated thread and some comments may be shown as answers.
David Martinez
Top achievements
Rank 1
David Martinez asked on 14 Oct 2010, 07:47 PM
I'd like that when the user press "Enter" on my RadNumericTextBox it would be the same as if he would give a click on a especific button.
The definition of my RadNumericTextBox is:

<telerik:RadNumericTextBox ID="radMyNumericTextBox" runat="server" Width="132px">
        <ClientEvents OnKeyPress="radMyNumericTextBox_KeyDown" />
</telerik:RadNumericTextBox>
My code is:
private void radMyNumericTextBox_KeyDown(object sender, KeyEventArgs e)

 

{

 

    if (e.KeyCode == Keys.Enter)

 

    {

        btnMyButton_Click(sender, e);

    }
}
Note: Actually if I press "Enter" in the RadNumericTextBox close's my window.
Any help?
Thank you very much.

David

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Oct 2010, 06:04 AM
Hi David,


Set the AutoPostBack property of the RadNumericTextBox to "True". And togle the AutoPostBack property based on the key pressed, in client-side OnKeyPress event. Here is the sample code.

aspx:
<telerik:RadNumericTextBox AutoPostBack="true" ID="numeric" runat="server" Type="Percent">
    <ClientEvents OnBlur="OnBlur" OnKeyPress="OnKeyPress" />
</telerik:RadNumericTextBox>


client code:
function OnKeyPress(sender, args) {
    if (args.get_keyCode() == 13) {
        sender.set_autoPostBack(true);
    }
    else {
        sender.set_autoPostBack(false);
    }
}


Regards,
Shinu.
0
David Martinez
Top achievements
Rank 1
answered on 15 Oct 2010, 05:58 PM
Thank you very much but I'm still having the same issue (when I press "Enter" the window close's and do nothing)....thanks any way.  :)
0
Dimo
Telerik team
answered on 21 Oct 2010, 03:19 PM
Hello David,

Judging by your code snippet, you seem to be confusing Javascript code syntax with C# code syntax. KeyPress is a client event and the handler should be a Javascript function. Please inspect the RadNumericTextBox client API and make sure you are implementing Javascript code correctly.

http://www.telerik.com/help/aspnet-ajax/input_clientsidebasics.html

http://www.telerik.com/help/aspnet-ajax/input_clientsideradnumerictextbox.html

http://www.telerik.com/help/aspnet-ajax/input_clientsideonkeypress.html


<%@ Page Language="C#" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server">
    <ClientEvents OnKeyPress="MyPress" />
</telerik:RadNumericTextBox>
 
<asp:Button ID="Button1" Text="button" runat="server" OnClientClick="return clicked()" />
 
<script type="text/javascript">
 
function MyPress(sender, args)
{
    if (args.get_keyCode() == 13)
    {
        $get("<%= Button1.ClientID %>").click();
        args.set_cancel(true);
    }
}
 
function clicked()
{
    alert("button clicked");
    return true; // set to false to prevent postback
}
 
</script>
 
</form>
</body>
</html>


Regards,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Input
Asked by
David Martinez
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
David Martinez
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or