文本框自动聚焦到其他文本框 [英] Textbox Focus to other textbox automatically

查看:100
本文介绍了文本框自动聚焦到其他文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我正在Asp.net,C#,SqlServer2005上工作.

我的登录页面上有3个文本框和一个提交"按钮

============================
用户名:TextBox1
DisplayName:Textbox2
密码:Textbox3


提交

============================

在此,我将Textbox1属性的AutoPostback设置为TRUE,并在Textbox1 TextchangedEvent中编写了代码.以便在Textbox2中显示全名....效果很好.


现在我的问题是文本框焦点问题......
当用户在Textbox1中输入用户名"时,下一个焦点"必须转到密码...",并避免在输入用户名后刷新页面.


请帮帮我,

谢谢.

Dear All,

Am Working on Asp.net, C#, SqlServer2005.

I have 3 Textboxes and a Submit Button on my Login Page

==============================
UserName : TextBox1
DisplayName : Textbox2
Password : Textbox3


Submit

==============================

In this I gave Textbox1 property as AutoPostback to TRUE and wrote code in Textbox1 TextchangedEvent. so that it dispalys a full name in Textbox2....its works fine.


Now My PROBLEM is Textbox Focus Problem......
When the user enters Username in Textbox1 and then the Next focus must go to Password... and avoid page refresh after entering username.


Please help me,

Thanks.

推荐答案

按所需顺序设置每个TextBox的TabIndex.


Set the TabIndex of each TextBox in a required sequence.


TextBox1.TabIndex=1;
TextBox2.TabIndex=2;





试试这个.让我知道这是否是您的解决方案.





Try this..let me know if this is your solution..


尝试使用AJAX.添加一个更新面板,并在TextBox 1的textchanged事件中将焦点设置为password文本框.

Try using AJAX. Add an update panel, and set focus to password textbox in textchanged event of TextBox 1.

<asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown" />
<asp:updatepanel id="updatePanel" runat="server" xmlns:asp="#unknown">
<contenttemplate>

<asp:textbox id="txtUserName" runat="server"></asp:textbox>
<asp:textbox id="txtDisplayName" runat="server"></asp:textbox>
<asp:textbox id="txtPassword" runat="server"></asp:textbox>

</contenttemplate>
</asp:updatepanel>


我认为,如果您在服务器端的事件中执行以下操作,它将起作用. [功能的最后一行很重要]

I think if you do the following in the event on server-side it will work. [LAST line of function is important]

protected void TextBox1_TextChanged(object sender, EventArgs e)
   {
       TextBox2.Text = TextBox1.Text;
       TextBox3.Focus();
   }


这篇关于文本框自动聚焦到其他文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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