HtmlForm.DefaultFocus Właściwość

Definicja

Pobiera lub ustawia kontrolkę na formularzu, aby wyświetlać jako kontrolkę z fokusem wejściowym po załadowaniu kontrolki 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

Wartość właściwości

String

Kontrolka ClientID w formularzu, która ma być wyświetlana jako kontrolka z fokusem wejściowym po załadowaniu HtmlForm . Wartością domyślną jest ciąg pusty ("").

Przykłady

Poniższy przykład kodu pokazuje, jak ustawić DefaultFocus właściwość tak, aby wyświetlała określoną kontrolkę w formularzu jako kontrolkę z fokusem wejściowym podczas ładowania formularza. Podczas Form1 renderowania zwróć uwagę, że punkt wstawiania jest umieszczony w TextBox1elemecie , wskazując, że TextBox1 jest to kontrolka z fokusem.

<%@ 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>

Uwagi

Użyj właściwości , DefaultFocus aby uzyskać dostęp do kontrolki w formularzu, aby wyświetlić jako kontrolkę z fokusem wejściowym po załadowaniu kontrolki HtmlForm . Kontrolki, które można wybrać, są wyświetlane z wizualnym sygnałem wskazującym, że mają fokus. Na przykład kontrolka TextBox z fokusem jest wyświetlana z punktem wstawiania umieszczonym wewnątrz.

Kontrolka z fokusem można również ustawić przy użyciu Focus metod lub SetFocus . Te metody mają pierwszeństwo przed właściwością DefaultFocus . Jeśli któraś z tych metod jest wywoływana w celu ustawienia kontrolki fokusem, wartość DefaultFocus właściwości jest ignorowana.

Dotyczy

Zobacz też