WebControl.TabIndex Property
Assembly: System.Web (in system.web.dll)
/** @property */ public short get_TabIndex () /** @property */ public void set_TabIndex (short value)
public function get TabIndex () : short public function set TabIndex (value : short)
Property Value
The tab index of the Web server control. The default is 0, which indicates that this property is not set.Use the TabIndex property to specify or determine the tab index of a Web server control on the Web Forms page. When you press the Tab key, the order in which the Web server controls receive focus is determined by the TabIndex property of each control. 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. If multiple controls share the same tab index, the controls will receive focus in the order they are declared on the Web Forms page. Finally, controls that have a tab index of zero are tabbed to in the order they are declared.
Note |
|---|
| Only controls with a nonzero tab index will render the tabindex attribute. |
You can remove a Web Server control from the tab order by setting the TabIndex property to a negative value.
Note |
|---|
| This property is supported only in Internet Explorer 4 and later. |
The following example illustrates how to use the TabIndex property of the WebControl to set the tab order of controls on the page.
Note |
|---|
| The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model. |
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <body> <h3>TabIndex Property of a Web Control<br></h3> <script Language="C#" runat="server"> void SubmitBtn1_Click(Object sender, EventArgs e) { SubmitBtn1.TabIndex = 0; TextBox1.TabIndex = (short)((TextBox1.Text=="") ? 0 : System.Int32.Parse(TextBox1.Text)); TextBox2.TabIndex = (short)((TextBox2.Text=="") ? 0 : System.Int32.Parse(TextBox2.Text)); TextBox3.TabIndex = (short)((TextBox3.Text=="") ? 0 : System.Int32.Parse(TextBox3.Text)); } </script> <form runat=server> Type in the numbers 1, 2, or 3 as the desired tab order for the following text boxes, <br> Click the Submit button, and <br> Tab through the text boxes to verify:<p> <asp:Button id="SubmitBtn1" OnClick="SubmitBtn1_Click" Text="Submit" runat="server"/> <p> <asp:TextBox id="TextBox1" BackColor="Pink" runat="server"/> <p> <asp:TextBox id="TextBox2" BackColor="LightBlue" runat="server"/> <p> <asp:TextBox id="TextBox3" BackColor="LightGreen" runat="server"/> <p> </form> </body> </html>
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Note