TextBox.AutoCompleteType Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą zachowanie autouzupełniania kontrolki TextBox .

public:
 virtual property System::Web::UI::WebControls::AutoCompleteType AutoCompleteType { System::Web::UI::WebControls::AutoCompleteType get(); void set(System::Web::UI::WebControls::AutoCompleteType value); };
[System.Web.UI.Themeable(false)]
public virtual System.Web.UI.WebControls.AutoCompleteType AutoCompleteType { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.AutoCompleteType : System.Web.UI.WebControls.AutoCompleteType with get, set
Public Overridable Property AutoCompleteType As AutoCompleteType

Wartość właściwości

AutoCompleteType

AutoCompleteType Jedna z wartości wyliczenia wskazująca zachowanie autouzupełniania dla kontrolkiTextBox. Wartość domyślna to None.

Atrybuty

Wyjątki

Wybrana wartość nie jest jedną z AutoCompleteType wartości wyliczenia.

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą AutoCompleteType wyliczenia określić kategorię Autouzupełnianie dla kontrolki TextBox .

Ważne

Ten przykład zawiera pole tekstowe, które akceptuje dane wejściowe użytkownika, co jest potencjalnym zagrożeniem bezpieczeństwa. Domyślnie ASP.NET strony sieci Web sprawdzają, czy dane wejściowe użytkownika nie zawierają skryptów ani elementów HTML. Aby uzyskać więcej informacji, zobacz Script Exploits Overview (Omówienie luk w zabezpieczeniach skryptów).


<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>AutoCompleteType example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <!-- You need to enable the AutoComplete feature on -->
      <!-- a browser that supports it (such as Internet   -->
      <!-- Explorer 5.0 and later) for this sample to     -->
      <!-- work. The AutoComplete lists are created after -->
      <!-- the Submit button is clicked.                  -->
    
      <h3>AutoCompleteType example</h3>
    
      Enter values in the text boxes and click the Submit <br/>
      button. <br/><br/> 
    
      <!-- The following TextBox controls have different  -->
      <!-- categories assigned to their AutoCompleteType  -->
      <!-- properties.                                    -->
      First Name:<br/>
      <asp:textbox id="FirstNameTextBox"
        autocompletetype="FirstName" 
        runat="server"/>
      <br/>
        
      Last Name:<br/>   
      <asp:textbox id="LastNameTextBox"
        autocompletetype="LastName" 
        runat="server"/>
      <br/>
      
      Email:<br/>   
      <asp:textbox id="EmailTextBox"
        autocompletetype="Email" 
        runat="server"/>
      <br/>
      
      <!-- The following TextBox controls have the same   -->
      <!-- categories assigned to their AutoCompleteType  -->
      <!-- properties. They share the same AutoComplete   -->
      <!-- list.                                          -->
      Phone Line #1:<br/>
      <asp:textbox id="Phone1TextBox"
        autocompletetype="HomePhone" 
        runat="server"/>
      <br/>
      
      Phone Line #2:<br/>
      <asp:textbox id="Phone2TextBox"
        autocompletetype="HomePhone" 
        runat="server"/>
      <br/>

    
      <!-- The following TextBox control has its          -->
      <!-- AutoCompleteType property set to               -->
      <!-- AutoCompleteType.None. All TextBox controls    -->
      <!-- with the same ID across different pages share  -->
      <!-- the same AutoComplete list.                    -->
      Category:<br/>   
      <asp:textbox id="CategoryTextBox"
        autocompletetype="None" 
        runat="server"/>
      <br/>
        
      <!-- The following TextBox control has the          -->
      <!-- AutoComplete feature disabled.                 -->
      Comments:<br/>   
      <asp:textbox id="CommentsTextBox"
        autocompletetype="Disabled" 
        runat="server"/>
      <br/>
      <br/><br/>  
      
      <asp:button id="SubmitButton"
        text="Submit"
        runat="Server"/>
    
    </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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>AutoCompleteType example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <!-- You need to enable the AutoComplete feature on -->
      <!-- a browser that supports it (such as Internet   -->
      <!-- Explorer 5.0 and later) for this sample to     -->
      <!-- work. The AutoComplete lists are created after -->
      <!-- the Submit button is clicked.                  -->
    
      <h3>AutoCompleteType example</h3>
    
      Enter values in the text boxes and click the Submit <br/>
      button. <br/><br/> 
    
      <!-- The following TextBox controls have different  -->
      <!-- categories assigned to their AutoCompleteType  -->
      <!-- properties.                                    -->
      First Name:<br/>
      <asp:textbox id="FirstNameTextBox"
        autocompletetype="FirstName" 
        runat="server"/>
      <br/>
        
      Last Name:<br/>   
      <asp:textbox id="LastNameTextBox"
        autocompletetype="LastName" 
        runat="server"/>
      <br/>
      
      Email:<br/>   
      <asp:textbox id="EmailTextBox"
        autocompletetype="Email" 
        runat="server"/>
      <br/>
      
      <!-- The following TextBox controls have the same   -->
      <!-- categories assigned to their AutoCompleteType  -->
      <!-- properties. They share the same AutoComplete   -->
      <!-- list.                                          -->
      Phone Line #1:<br/>
      <asp:textbox id="Phone1TextBox"
        autocompletetype="HomePhone" 
        runat="server"/>
      <br/>
      
      Phone Line #2:<br/>
      <asp:textbox id="Phone2TextBox"
        autocompletetype="HomePhone" 
        runat="server"/>
      <br/>

    
      <!-- The following TextBox control has its          -->
      <!-- AutoCompleteType property set to               -->
      <!-- AutoCompleteType.None. All TextBox controls    -->
      <!-- with the same ID across different pages share  -->
      <!-- the same AutoComplete list.                    -->
      Category:<br/>   
      <asp:textbox id="CategoryTextBox"
        autocompletetype="None" 
        runat="server"/>
      <br/>
        
      <!-- The following TextBox control has the          -->
      <!-- AutoComplete feature disabled.                 -->
      Comments:<br/>   
      <asp:textbox id="CommentsTextBox"
        autocompletetype="Disabled" 
        runat="server"/>
      <br/>
      <br/><br/>  
      
      <asp:button id="SubmitButton"
        text="Submit"
        runat="Server"/>
    
    </form>
  </body>
</html>

Uwagi

Aby ułatwić wprowadzanie danych, program Microsoft Internet Explorer 5 lub nowszy oraz inne przeglądarki obsługują funkcję określaną jako Autouzupełnianie. Autouzupełnianie monitoruje pole tekstowe i tworzy listę wartości wprowadzonych przez użytkownika. Gdy użytkownik wróci do pola tekstowego w późniejszym czasie, zostanie wyświetlona lista. Zamiast ponownie wpisywać wcześniej wprowadzoną wartość, użytkownik może po prostu wybrać wartość z tej listy. AutoCompleteType Użyj właściwości , aby kontrolować zachowanie funkcji autouzupełniania dla kontrolkiTextBox. Wyliczenie System.Web.UI.WebControls.AutoCompleteType służy do reprezentowania wartości, które można zastosować do AutoCompleteType właściwości .

Uwaga

Nie wszystkie przeglądarki obsługują funkcję autouzupełniania. Sprawdź w przeglądarce, aby określić zgodność.

Domyślnie AutoCompleteType właściwość kontrolki jest ustawiona TextBox na AutoCompleteType.Nonewartość . Dzięki temu ustawieniu kontrolka TextBox udostępnia listę innym TextBox kontrolkom z tą samą ID właściwością na różnych stronach. Możesz również udostępnić listę między kontrolkami TextBox w oparciu o kategorię zamiast ID właściwości. Po ustawieniu AutoCompleteType właściwości na jedną z wartości kategorii (takich jak AutoCompleteType.FirstName, AutoCompleteType.LastNameitd.) wszystkie TextBox kontrolki z tą samą kategorią mają tę samą listę. Funkcję TextBox Autouzupełniania dla kontrolki można wyłączyć, ustawiając AutoCompleteType właściwość na AutoCompleteType.Disabled.

Zapoznaj się z dokumentacją przeglądarki, aby uzyskać szczegółowe informacje na temat konfigurowania i włączania funkcji autouzupełniania. Aby na przykład włączyć funkcję Autouzupełnianie w programie Internet Explorer w wersji 5 lub nowszej, wybierz pozycję Opcje internetowe z menu Narzędzia , a następnie wybierz kartę Zawartość . Kliknij przycisk Autouzupełnianie , aby wyświetlić i zmodyfikować różne opcje przeglądarki dla funkcji Autouzupełnianie.

Aby uzyskać więcej informacji na temat funkcji autouzupełniania w programie Internet Explorer, zobacz Używanie autouzupełniania w formularzach HTML.

Tej właściwości nie można ustawić za pomocą motywów ani motywów arkusza stylów. Aby uzyskać więcej informacji, zobacz ThemeableAttribute tematy i ASP.NET motywy i skórki.

Dotyczy

Zobacz też