当我按Enter键时,如何将控件从文本框移至按钮? [英] How to move the control from textbox to button when i press enter key?

查看:99
本文介绍了当我按Enter键时,如何将控件从文本框移至按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的登录页面中,输入用户名和密码后,如何使用Enter键而不是使用登录按钮进行登录?

In my login page,after giving userid and password how to login using enter key instead of using login button?
How to move the control from textbox to button when i press enter key?

推荐答案

您需要一个带有默认焦点的提交按钮.为此,您需要为页面添加"DefaultButton" 属性.

从ASP.NET 2.0开始,据说已为页面定义了默认按钮".通过简单地将"defaultbutton"属性指定为要触发事件的<asp:Button>的ID,即可完成工作.
可以在form标记的Form级别以及<asp:panel>定义标记的面板级别指定defaultbutton属性.在面板级别指定时,对于面板内部的那些控件,将覆盖表单级别设置

示例示例:
You need a submit button with default focus on it. For that, you need to add "DefaultButton" property for the page.

In ASP.NET 2.0 onwards, it''s said to have "Default Button" defined for the page. By simply specifying the "defaultbutton" property to the ID of the <asp:Button>, whose event you want to fire, your job is done.
The defaultbutton property can be specified at the Form level in the form tag as well as at panel level in the <asp:panel> definition tag. The form level setting is overridden when specified at the panel level, for those controls that are inside the panel

Sample example:
<form id="Form1"
    defaultbutton="SubmitButton"
    defaultfocus="TextBox1"
    runat="server">



参考:
ASP.NET DefaultButton属性 [默认"按钮的示例用法 [ ^ ]

不需要任何关键代码左右.使用上面的命令,enter press的默认行为会将其按该按钮单击的定义进行定向.



Refer:
ASP.NET DefaultButton Property[^]
Sample usage of Default button[^]

No need of any key code or so. Using above, default behavior of enter press would direct it as defined for that button click.



您必须在textbox1_KeyDown事件中进行编码

Hi,
You have to do the coding in the textbox1_KeyDown Event

Public void textbox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        //Your Code
        //Button Click event code
    }
}



希望对您有帮助.



Hope this will help you.


这篇关于当我按Enter键时,如何将控件从文本框移至按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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