WebControl.TabIndex プロパティ

定義

Web サーバー コントロールのタブ インデックスを取得または設定します。

public:
 virtual property short TabIndex { short get(); void set(short value); };
public virtual short TabIndex { get; set; }
member this.TabIndex : int16 with get, set
Public Overridable Property TabIndex As Short

プロパティ値

Web サーバー コントロールのタブ インデックス。 既定値は 0 です。このプロパティが設定されていないことを示します。

例外

指定したタブ インデックスが、-32768 から 32767 の間にありません。

次の例は、 の プロパティを TabIndex 使用して、ページ上の WebControl コントロールのタブ オーダーを設定する方法を示しています。

注意

次のコード サンプルでは、単一ファイルのコード モデルを使用しており、分離コード ファイルに直接コピーすると正しく動作しない場合があります。 このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。 Web Forms コード モデルの詳細については、「ASP.NET Web Forms ページ コード モデル」を参照してください。

重要

この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。 既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。 詳細については、「スクリプトによる攻略の概要」を参照してください。

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>Enabled Property Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>TabIndex Property of a Web Control<br /></h3>

    <p>
        Enter a number (1, 2, or 3) in each text box, <br /> 
        click the Submit button to set the TabIndexes, then <br /> 
        click on the page and tab through the page to verify.
    </p>
 
    <p><asp:Button id="SubmitBtn1" OnClick="SubmitBtn1_Click" 
            Text="Submit" runat="server"/>
    </p>

    <p><asp:TextBox id="TextBox1" BackColor="Pink" 
            runat="server"/>
    </p>
    <p><asp:TextBox id="TextBox2" BackColor="LightBlue" 
            runat="server"/>
    </p>
    <p><asp:TextBox id="TextBox3" BackColor="LightGreen" 
            runat="server"/>
    </p>  
     
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>Enabled Property Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>TabIndex Property of a Web Control<br /></h3>

    <p>
        Enter a number (1, 2, or 3) in each text box, <br /> 
        click the Submit button to set the TabIndexes, then <br /> 
        click on the page and tab through the page to verify.
    </p>
 
    <asp:Button id="SubmitBtn1" OnClick="SubmitBtn1_Click" 
        Text="Submit" runat="server"/>
    <p>
        <asp:TextBox id="TextBox1" BackColor="Pink" 
            runat="server"/>
    </p>
    <p>
        <asp:TextBox id="TextBox2" BackColor="LightBlue" 
            runat="server"/>
    </p>
    <p>
        <asp:TextBox id="TextBox3" BackColor="LightGreen" 
            runat="server"/>
    </p>  

    </div>
    </form>
</body>
</html>

注釈

プロパティを使用して、TabIndexWeb Forms ページの Web サーバー コントロールのタブ インデックスを指定または決定します。 キーを Tab 押すと、Web サーバー コントロールがフォーカスを受け取る順序は、各コントロールの プロパティによって TabIndex 決まります。 ページが最初に読み込まれるとき、キーが押されたときにフォーカスを受け取る最初の Tab 項目はアドレス バーです。 次に、Web Forms ページ上のコントロールは、各コントロールの プロパティの値に基づいて、最小の正の 0 以外のTabIndex値から始まる昇順にタブ付けされます。 複数のコントロールが同じタブ インデックスを共有している場合、コントロールはWeb Forms ページで宣言された順序でフォーカスを受け取ります。 最後に、タブ インデックスが 0 のコントロールは、宣言された順序で にタブ付けされます。

注意

0 以外のタブ インデックスを持つコントロールのみが 属性を tabindex レンダリングします。

プロパティを負の値に設定 TabIndex することで、タブ オーダーから Web サーバー コントロールを削除できます。

注意

このプロパティは、Internet Explorer 4 以降でのみサポートされています。

適用対象

こちらもご覧ください