将焦点设置为文本框中的按钮? [英] Setting focus to a button from text box?

查看:79
本文介绍了将焦点设置为文本框中的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有一些文本框和按钮.

I have a few text boxes and buttons on my form.

假设txtBox1在btnSubmit1旁边,txtBox2在btnSubmit2旁边,txtBox3在btnSubmit3旁边.

Lets say txtBox1 is next to btnSubmit1, txtBox2 is next to btnSubmit2, txtBox3 is next to btnSubmit3.

当用户开始在txtBox3中键入内容时,如何将焦点设置在btnSubmit3上.含义......如果用户在文本框中键入内容,则程序将在用户按下Enter键时知道要触发哪个按钮.

How can I set the focus on btnSubmit3 when the user starts to type something in txtBox3. Meaning..... if a user type in a text box the program will know what button to fire when the user press the enter key.

推荐答案

如果使用面板,则应该能够设置默认按钮.我不确定它是Win Form应用程序还是Web Forms应用程序,但这是您应该如何使用Web Forms的方法:

If you use a panel, you should be able to set a defaultbutton. I´m not sure if it´s an win forms application or a web forms application, but this is how you should do it with web forms:

<asp:Panel id="panel1" runat="server" DefaultButton="Button1">
   <asp:TextBox id="textbox1" runat="server" />
   <asp:Button id="Button1" runat="server" Text="Button 1" />
</asp:Panel>

<asp:Panel id="panel2" runat="server" DefaultButton="Button2">
   <asp:TextBox id="textbox2" runat="server" />
   <asp:Button id="Button2" runat="server" Text="Button 2" />
</asp:Panel>

<asp:Panel id="panel3" runat="server" DefaultButton="Button3">
   <asp:TextBox id="textbox3" runat="server" />
   <asp:Button id="Button3" runat="server" Text="Button 3" />
</asp:Panel>

这篇关于将焦点设置为文本框中的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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