WebControl.TabIndex プロパティ
アセンブリ: System.Web (system.web.dll 内)
構文
/** @property */ public short get_TabIndex () /** @property */ public void set_TabIndex (short value)
Web サーバー コントロールのタブ インデックス。既定値は 0 です。このプロパティが設定されていないことを示します。
解説
TabIndex プロパティを使用して、Web フォーム ページ上の Web サーバー コントロールのタブ インデックスを指定または確認します。Tab キーを押したときの、Web サーバー コントロールがフォーカスを受け取る順序は、各コントロールの TabIndex プロパティによって決定されます。ページが最初に読み込まれるとき、Tab キーが押されて最初にフォーカスを受け取る項目はアドレス バーです。次に、各コントロールの TabIndex プロパティの値に基づいて、Web フォーム ページのコントロール間を Tab キーで昇順に移動します。Tab キーによる移動は、0 以外の最小の正の値から開始されます。複数のコントロールが同じタブ インデックスを共有している場合、コントロールは、Web フォーム ページで宣言されている順序でフォーカスを受け取ります。最後に、0 のタブ インデックスを持つコントロール間を宣言された順序で Tab キーにより移動します。
メモ |
---|
WebControl の TabIndex プロパティを使用して、ページ上のコントロールのタブ オーダーを設定する方法の例を次に示します。
メモ |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ 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>
<%@ 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>
<%@ 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>
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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- WebControl.TabIndex プロパティのページへのリンク