Click here to Skip to main content
15,916,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>
Posted
Comments
CodingLover 10-Apr-15 2:43am    
If you try it out from index 2 to index 3, is it work?
Dawood Abbas 10-Apr-15 3:04am    
yes.its working properly,but when iam going from 0 to 1 but then its not going to 1,its going to address bar then from there coming to 1.

1 solution

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:-

XML
<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:-

C#
protected void Page_Load(object sender, EventArgs e)
{
    txtName.Focus();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900