如何检查是否enterkey是在asp.net一个TextBox pssed $ P $ [英] How to check if enterkey is pressed in a TextBox in asp.net

查看:131
本文介绍了如何检查是否enterkey是在asp.net一个TextBox pssed $ P $的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个接受的格式为MM / DD / YYYY日期asp.net文本框。输入日期后,我会打进入key.if回车键,我需要执行服务器端code.How我们能做到这一点?

I have a asp.net Text Box which accepts date in the format MM/DD/YYYY. After entering the date i will hit enter key.if enter key i need to execute server side code.How can we achieve this ?

用文本框的问题是,它会火,只有当它失去焦点的文本已改变的事件。

The problem with Text box is it will fire the Text Changed event only if it looses the focus.

推荐答案

您可以使用的 Panel.DefaultButton 属性自动点击一个按钮,当用户presses Enter键。

You can use the Panel.DefaultButton property to automatically click a button when the user presses Enter.

例如:

<asp:Panel Id="panel1" runat="server" DefaultButton="btnSubmit">
  <asp:TextBox Id="txtDate" runat="server" />
  <asp:Button Id="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" runat="server" />
</asp:Panel>

如果你不希望显示按钮,可以设置其 =风格显示:无

If you don't want to show the button, you can set its style="display: none".

这篇关于如何检查是否enterkey是在asp.net一个TextBox pssed $ P $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆