Sdílet prostřednictvím


HtmlForm.DefaultFocus Vlastnost

Definice

Získá nebo nastaví ovládací prvek ve formuláři, který se zobrazí jako ovládací prvek se vstupním fokusem při HtmlForm načtení ovládacího prvku.

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

Hodnota vlastnosti

String

Ovládací ClientID prvek ve formuláři, který se má zobrazit jako ovládací prvek se vstupním fokusem při HtmlForm načtení. Výchozí hodnota je prázdný řetězec ("").

Příklady

Následující příklad kódu ukazuje, jak nastavit DefaultFocus vlastnost pro zobrazení zadaného ovládacího prvku ve formuláři jako ovládací prvek s fokusem vstupu při načtení formuláře. Když Form1 se vykresluje, všimněte si, že kurzor je umístěný v TextBox1, což znamená, že TextBox1 je ovládací prvek s 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>

Poznámky

DefaultFocus Vlastnost slouží k přístupu k ovládacímu prvku ve formuláři, aby se při načtení ovládacího prvku zobrazil jako ovládací prvek se vstupním fokusemHtmlForm. Ovládací prvky, které lze vybrat, se zobrazí s vizuálním upozorněním, které indikují, že mají fokus. Například TextBox ovládací prvek s fokusem se zobrazí s kurzorem umístěným uvnitř.

Ovládací prvek s fokusem lze nastavit také pomocí Focus metod nebo SetFocus metod. Tyto metody mají přednost před DefaultFocus vlastností. Pokud se volá některý z těchto metod k nastavení ovládacího prvku s fokusem, hodnota DefaultFocus vlastnosti je ignorována.

Platí pro

Viz také