ImageButton.ValidationGroup Właściwość

Definicja

Pobiera lub ustawia grupę kontrolek, dla których ImageButton kontrolka powoduje walidację, gdy publikuje z powrotem na serwerze.

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

Wartość właściwości

String

Grupa kontrolek, dla których kontrolka ImageButton powoduje walidację po wysłaniu jej z powrotem do serwera. Wartością domyślną jest ciąg pusty ("").

Implementuje

Atrybuty

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą ValidationGroup właściwości określić kontrolki do sprawdzania poprawności, kiedy kontrolka ImageButton publikuje z powrotem na serwerze. Strona zawiera trzy pola tekstowe do przechwytywania danych od użytkownika i trzech RequiredFieldValidator kontrolek w celu zapewnienia, że użytkownik nie pozostawi pustego pola tekstowego. Kontrolki RequiredFieldValidator dla pierwszych dwóch pól tekstowych znajdują się w PersonalInfoGroup grupie weryfikacji, a kontrolka RequiredFieldValidator trzeciego pola tekstowego znajduje się LocationInfoGroup w grupie walidacji. Po ImageButton1 kliknięciu są weryfikowane tylko kontrolki w grupie PersonalInfoGroup weryfikacji. Po ImageButton2 kliknięciu zostanie zweryfikowana tylko kontrolka w grupie LocationInfoGroup sprawdzania poprawności.

<%@ 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 id="head1" runat="server">
  <title>ImageButton.ValidationGroup Example</title>
</head>
<body>
  <form id="form1" runat="server">
  
    <h3>ImageButton.ValidationGroup Example</h3>

    <asp:label id="NameLabel" 
      text="Enter your name:"
      runat="Server"
      AssociatedControlID="NameTextBox">
    </asp:label>

    &nbsp
    
    <asp:textbox id="NameTextBox" 
      runat="Server">
    </asp:textbox>

    &nbsp

    <asp:requiredfieldvalidator id="RequiredFieldValidator1"
      controltovalidate="NameTextBox"
      validationgroup="PersonalInfoGroup"
      errormessage="Enter your name."
      runat="Server">
    </asp:requiredfieldvalidator>
    
    <br /><br />
    
    <asp:label id="AgeLabel" 
      text="Enter your age:"
      runat="Server"
      AssociatedControlID="AgeTextBox">
    </asp:label>

    &nbsp
    
    <asp:textbox id="AgeTextBox" 
      runat="Server">
    </asp:textbox>

    &nbsp

    <asp:requiredfieldvalidator id="RequiredFieldValidator2"
      controltovalidate="AgeTextBox"
      validationgroup="PersonalInfoGroup"
      errormessage="Enter your age."
      runat="Server">
    </asp:requiredfieldvalidator>
    
    <br /><br />

    <!--When ImageButton1 is clicked, only validation
    controls that are a part of PersonalInfoGroup
    are validated.-->
    <asp:imagebutton id="ImageButton1" 
      alternatetext="Validate PersonalInfoGroup controls" 
      imageurl="Images/ImageButton1.JPG"
      causesvalidation="true"
      validationgroup="PersonalInfoGroup"
      runat="Server" />
      
    <br /><br />
      
    <asp:label id="CityLabel" 
      text="Enter your city of residence:"
      runat="Server"
      AssociatedControlID="CityTextBox">
    </asp:label>

    &nbsp
    
    <asp:textbox id="CityTextBox" 
      runat="Server">
    </asp:textbox>

    &nbsp

    <asp:requiredfieldvalidator id="RequiredFieldValidator3"
      controltovalidate="CityTextBox"
      validationgroup="LocationInfoGroup"
      errormessage="Enter a city name."
      runat="Server">
    </asp:requiredfieldvalidator>
    
    <br /><br />

    <!--When ImageButton2 is clicked, only validation
    controls that are a part of LocationInfoGroup
    are validated.-->
    <asp:imagebutton id="ImageButton2" 
      alternatetext="Validate LocationInfoGroup controls" 
      imageUrl="Images/ImageButton2.JPG"
      causesvalidation="true"
      validationgroup="LocationInfoGroup"
      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 id="head1" runat="server">
  <title>ImageButton.ValidationGroup Example</title>
</head>
<body>
  <form id="form1" runat="server">
  
    <h3>ImageButton.ValidationGroup Example</h3>

    <asp:label id="NameLabel" 
      text="Enter your name:"
      runat="Server" AssociatedControlID="NameTextBox">
    </asp:label>

    &nbsp
    
    <asp:textbox id="NameTextBox" 
      runat="Server">
    </asp:textbox>

    &nbsp

    <asp:requiredfieldvalidator id="RequiredFieldValidator1"
      controltovalidate="NameTextBox"
      validationgroup="PersonalInfoGroup"
      errormessage="Enter your name."
      runat="Server">
    </asp:requiredfieldvalidator>
    
    <br /><br />
    
    <asp:label id="AgeLabel" 
      text="Enter your age:"
      runat="Server"
      AssociatedControlID="AgeTextBox">
    </asp:label>

    &nbsp
    
    <asp:textbox id="AgeTextBox" 
      runat="Server">
    </asp:textbox>

    &nbsp

    <asp:requiredfieldvalidator id="RequiredFieldValidator2"
      controltovalidate="AgeTextBox"
      validationgroup="PersonalInfoGroup"
      errormessage="Enter your age."
      runat="Server">
    </asp:requiredfieldvalidator>
    
    <br /><br />

    <!--When ImageButton1 is clicked, only validation
    controls that are a part of PersonalInfoGroup
    are validated.-->
    <asp:imagebutton id="ImageButton1" 
      alternatetext="Validate PersonalInfoGroup controls" 
      imageurl="Images/ImageButton1.JPG"
      causesvalidation="true"
      validationgroup="PersonalInfoGroup"
      runat="Server" />
      
    <br /><br />
      
    <asp:label id="CityLabel" 
      text="Enter your city of residence:"
      runat="Server"
      AssociatedControlID="CityTextBox">
    </asp:label>

    &nbsp
    
    <asp:textbox id="CityTextBox" 
      runat="Server">
    </asp:textbox>

    &nbsp

    <asp:requiredfieldvalidator id="RequiredFieldValidator3"
      controltovalidate="CityTextBox"
      validationgroup="LocationInfoGroup"
      errormessage="Enter a city name."
      runat="Server">
    </asp:requiredfieldvalidator>
    
    <br /><br />

    <!--When ImageButton2 is clicked, only validation
    controls that are a part of LocationInfoGroup
    are validated.-->
    <asp:imagebutton id="ImageButton2" 
      alternatetext="Validate LocationInfoGroup controls" 
      imageUrl="Images/ImageButton2.JPG"
      causesvalidation="true"
      validationgroup="LocationInfoGroup"
      runat="Server" />

  </form>
</body>
</html>

Uwagi

Grupy walidacji umożliwiają przypisywanie kontrolek weryfikacji na stronie do określonej kategorii. Każda grupa walidacji może być weryfikowana niezależnie od innych grup walidacji na stronie. ValidationGroup Użyj właściwości , aby określić nazwę grupy weryfikacji, dla której ImageButton kontrolka powoduje walidację, gdy publikuje z powrotem na serwerze. Ta właściwość ma wpływ tylko wtedy, gdy wartość CausesValidation właściwości jest ustawiona na truewartość . Po określeniu ValidationGroup wartości dla właściwości tylko kontrolki weryfikacji, które są częścią określonej grupy, są weryfikowane, gdy ImageButton kontrolka publikuje z powrotem na serwerze. Jeśli nie określisz wartości dla tej właściwości i CausesValidation właściwość zostanie ustawiona na truewartość , wszystkie kontrolki walidacji na stronie, które nie są przypisane do grupy sprawdzania poprawności, zostaną zweryfikowane, gdy kontrolka publikuje z powrotem na serwerze.

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ż