如何在asp.net中设置url的tab索引 [英] How to set tab index for url in asp.net

查看:42
本文介绍了如何在asp.net中设置url的tab索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表单中,我有一些文本框,从一个文本框导航到另一个,我使用键盘上的tab键,但是当我从第一个Textbox(Name)按Tab键时,光标导航到url bar然后从即使我以数字方式将tabindex属性设置为所有控件,也会导航到其他文本框。



< asp:TextBox ID = txtNamerunat =serverTabIndex =0>< / asp:TextBox> 
< asp:TextBox ID =txtSorunat =serverTabIndex =1>< / asp:TextBox>< br />
< asp:TextBox ID =txtAddrunat =serverTabIndex =2>< / asp:TextBox>
< asp:dropdownlist ID =ddlArearunat =serverTabIndex =3class =drop>< / asp:dropdownlist>

解决方案

根据MSDN: -



引用:

最初加载页面时,按下Tab键时获得焦点的第一个项目是地址栏。接下来,Web窗体页面上的控件按升序排列,基于每个控件的TabIndex属性的值,从最小的正非零值开始。





此外,使用TabIndex为0声明的控件最后都是选项卡。所以,改变你的结果如下: -



 <  < span class =code-leadattribute> asp:TextBox     ID   =  txtName    runat   =  server    TabIndex   =  1 < span class =code-keyword>>  <   / asp:TextBox  < span class =code-keyword>>  
< asp:TextBox ID = txtSo runat = 服务器 TabIndex = 2 > < / asp:TextBox > < br / >
< asp:TextBox ID = txtAdd runat = server TabIndex = 3 > < / asp:TextBox >
< asp: DropDownList ID = ddlArea runat = server TabIndex = 4 class = drop >
< / asp:DropDownList >





仍然,如果您没有设置任何默认焦点,默认情况下它会标签到地址栏,因此要设置任何控制焦点,您可以调用焦点方法: -



< pre lang =cs> protected void Page_Load( object sender,EventArgs e)
{
txtName.Focus();
}


In my form I have some textboxes, to navigate from one textbox to other, I am using 'tab' key from keyboard, but when I press tab from first Textbox(Name) then the cursor navigates to the url bar then from there navigates to other textboxes as set, even if I set the tabindex property to all the controls numerically.

<asp:TextBox ID="txtName" runat="server" TabIndex="0"></asp:TextBox>
<asp:TextBox ID="txtSo" runat="server" TabIndex="1"></asp:TextBox><br />
<asp:TextBox ID="txtAdd" runat="server" TabIndex="2"></asp:TextBox>
<asp:dropdownlist ID="ddlArea" runat="server" TabIndex="3" class="drop"></asp:dropdownlist>

解决方案

According to MSDN:-

Quote:

When a page is initially loaded, the first item that receives focus when the Tab key is pressed is the address bar. Next, the controls on the Web Forms page are tabbed to in ascending order, based on the value of the TabIndex property of each control, starting with the smallest positive, nonzero value.



Also, the controls who are declared with TabIndex of 0 are tabbed at the last. So, change your marup like this:-

<asp:TextBox ID="txtName" runat="server" TabIndex="1"></asp:TextBox>
<asp:TextBox ID="txtSo" runat="server" TabIndex="2"></asp:TextBox><br />
<asp:TextBox ID="txtAdd" runat="server" TabIndex="3"></asp:TextBox>
<asp:DropDownList ID="ddlArea" runat="server" TabIndex="4" class="drop">
</asp:DropDownList>



Still, if you don't set any default focus, by default it will tab to the address bar, so to set any control focus you can call the Focus method:-

protected void Page_Load(object sender, EventArgs e)
{
    txtName.Focus();
}


这篇关于如何在asp.net中设置url的tab索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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