WebControl.TabIndex Property
Gets or sets the tab index of the Web server control.
[Visual Basic] Public Overridable Property TabIndex As Short [C#] public virtual short TabIndex {get; set;} [C++] public: __property virtual short get_TabIndex(); public: __property virtual void set_TabIndex(short); [JScript] public function get TabIndex() : Int16; public function set TabIndex(Int16);
Property Value
The tab index of the Web server control. The default is 0, which indicates that this property is not set.
Exceptions
| Exception Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The specified tab index is not between -32768 and 32767. |
Remarks
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 addess 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.
Example
[Visual Basic, C#, JScript] The following example illustrates how to use the TabIndex property of the WebControl to set the tab order of controls on the page.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <body> <h3>TabIndex Property of a Web Control<br></h3> <script Language="VB" runat="server"> Sub SubmitBtn1_Click(sender As Object, e As EventArgs) SubmitBtn1.TabIndex = 0 If TextBox1.Text = "" Then TextBox1.TabIndex = 0 Else TextBox1.TabIndex = System.Int16.Parse(TextBox1.Text) End If If TextBox2.Text = "" Then TextBox2.TabIndex = 0 Else TextBox2.TabIndex = System.Int16.Parse(TextBox2.Text) End If If TextBox3.Text = "" Then TextBox3.TabIndex = 0 Else TextBox3.TabIndex = System.Int16.Parse(TextBox3.Text) End If End Sub </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> [C#] <%@ 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> [JScript] <%@ Page Language="JScript" AutoEventWireup="True" %> <html> <body> <h3>TabIndex Property of a Web Control<br></h3> <script Language="JSCRIPT" runat="server"> function SubmitBtn1_Click(sender : Object, e : EventArgs){ SubmitBtn1.TabIndex = 0 if(TextBox1.Text == "") TextBox1.TabIndex = 0 else TextBox1.TabIndex = System.Int16.Parse(TextBox1.Text) if(TextBox2.Text == "") TextBox2.TabIndex = 0 else TextBox2.TabIndex = System.Int16.Parse(TextBox2.Text) if(TextBox3.Text == "") TextBox3.TabIndex = 0 else TextBox3.TabIndex = System.Int16.Parse(TextBox3.Text) } </script> <form runat=server> Type in the numbers 1, 2, or 3 : 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>
[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
WebControl Class | WebControl Members | System.Web.UI.WebControls Namespace