HtmlForm.DefaultFocus プロパティ

定義

HtmlForm コントロールが読み込まれたときに入力フォーカスのあるコントロールとして表示するフォーム上のコントロールを取得または設定します。

public:
 property System::String ^ DefaultFocus { System::String ^ get(); void set(System::String ^ value); };
public string DefaultFocus { get; set; }
member this.DefaultFocus : string with get, set
Public Property DefaultFocus As String

プロパティ値

String

ClientID が読み込まれたときに入力フォーカスのあるコントロールとして表示するフォーム上のコントロールの HtmlForm。 既定値は空の文字列 ("") です。

次のコード例は、フォームが DefaultFocus 読み込まれるときに入力フォーカスを持つコントロールとしてフォームに指定したコントロールを表示するようにプロパティを設定する方法を示しています。 レンダリング時 Form1 に、カーソルがフォーカスを TextBox1持つコントロールであることを TextBox1 示す位置に配置されていることに注意してください。

<%@ 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 Page_Load(object sender, System.EventArgs e)
  {
    
    // Set the text of the two label controls.
    Label1.Text = "The DefaultButton property is set to "
                + Form1.DefaultButton.ToString() + "<br/>";
    Label2.Text = "The DefaultFocus property is set to "
                + Form1.DefaultFocus.ToString();
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

    <title>HtmlForm DefaultButton and DefaultFocus Properties Example</title>

</head>

<body>

  <form id="Form1"
        defaultbutton="SubmitButton"
        defaultfocus="TextBox1"
        runat="server">
    
    <h3>HtmlForm DefaultButton and DefaultFocus Properties Example</h3>        
  
    TextBox1:
    <asp:textbox id="TextBox1"
                 autopostback="true" 
                 runat="server">
    </asp:textbox>
  
    <br />
  
    TextBox2:
    <asp:textbox id="TextBox2"
                 autopostback="true" 
                 runat="server">
    </asp:textbox>
  
    <br /><br />
  
    <asp:button id="SubmitButton"
                text="Submit" 
                runat="server">
    </asp:button>
  
    <asp:button id="CancelButton" 
                text="Cancel"
                runat="server">
    </asp:button>
  
    <hr />
  
    <asp:label id="Label1"
               runat="Server">
    </asp:label>
  
    <asp:label id="Label2"
               runat="Server">
    </asp:label>

  </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 Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    
    ' Set the text of the two label controls.
    Label1.Text = "The DefaultButton property is set to " _
                  & Form1.DefaultButton.ToString & "<br/>"
    Label2.Text = "The DefaultFocus property is set to " _
                  & Form1.DefaultFocus.ToString
  End Sub
     
 </script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

    <title>HtmlForm DefaultButton and DefaultFocus Properties Example</title>

</head>

<body>

  <form id="Form1"
        defaultbutton="SubmitButton"
        defaultfocus="TextBox1"
        runat="server">
    
    <h3>HtmlForm DefaultButton and DefaultFocus Properties Example</h3>        
  
    TextBox1:
    <asp:textbox id="TextBox1"
                 autopostback="true" 
                 runat="server">
    </asp:textbox>
  
    <br />
  
    TextBox2:
    <asp:textbox id="TextBox2"
                 autopostback="true" 
                 runat="server">
    </asp:textbox>
  
    <br /><br />
  
    <asp:button id="SubmitButton"
                text="Submit" 
                runat="server">
    </asp:button>
  
    <asp:button id="CancelButton" 
                text="Cancel"
                runat="server">
    </asp:button>
  
    <hr />
  
    <asp:label id="Label1"
               runat="Server">
    </asp:label>
  
    <asp:label id="Label2"
               runat="Server">
    </asp:label>

  </form>

</body>

</html>

注釈

このプロパティを DefaultFocus 使用して、フォーム上のコントロールにアクセスし、コントロールが読み込まれるときに入力フォーカスを HtmlForm 持つコントロールとして表示します。 選択できるコントロールは、フォーカスがあることを示す視覚的なキューと共に表示されます。 たとえば、フォーカスのある TextBox コントロールは、その中にカーソルが配置された状態で表示されます。

フォーカスのあるコントロールは、or SetFocus メソッドをFocus使用して設定することもできます。 これらのメソッドは、プロパティよりも DefaultFocus 優先されます。 これらのメソッドのいずれかが呼び出されてフォーカスを持つコントロールを設定する場合、プロパティの DefaultFocus 値は無視されます。

適用対象

こちらもご覧ください