Share via


HtmlButton.ValidationGroup 속성

정의

서버에 포스트백될 때 HtmlButton이 유효성 검사를 수행할 컨트롤 그룹을 가져오거나 설정합니다.

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

속성 값

String

서버에 포스트백될 때 HtmlButton 컨트롤이 유효성 검사를 수행할 컨트롤 그룹입니다. 기본값은 빈 문자열("")로, 이 속성이 설정되지 않았음을 나타냅니다.

예제

다음 코드 예제에서는 컨트롤이 서버에 다시 게시 될 때 HtmlButton 유효성을 검사 하는 컨트롤을 지정 하는 속성을 사용 ValidationGroup 하는 방법을 보여 줍니다. 페이지에는 사용자의 데이터를 캡처하는 두 개의 텍스트 상자와 사용자가 텍스트 상자를 비워 두지 않도록 하는 두 개의 RequiredFieldValidator 컨트롤이 포함되어 있습니다. RequiredFieldValidator 첫 번째 텍스트 상자의 컨트롤은 CityInfoGroup 유효성 검사 그룹에 있고 RequiredFieldValidator 두 번째 상자에 대한 컨트롤은 StateInfoGroup 유효성 검사 그룹에 있습니다. CityQueryButton 클릭하면 유효성 검사 그룹의 컨트롤 CityInfoGroup 만 유효성이 검사됩니다. StateQueryButton 클릭하면 유효성 검사 그룹의 컨트롤 StateInfoGroup 만 유효성이 검사됩니다.

<%@ 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 SubmitButton_Click(Object sender, EventArgs e)
  {
    // Determine which button was clicked.
    switch (((HtmlButton)sender).ID)
    {
        
      case "CityQueryButton":

          if (CityReqValidator.IsValid)
          {
              // Indicate that the city query was selected.
              Message.InnerHtml = "You have chosen to run a query for the following city: " +
                                  CityTextBox.Value;
          }
        
        break;
        
      case "StateQueryButton":

          if (StateReqValidator.IsValid)
          {
              // Indicate that the state query was selected.
              Message.InnerHtml = "You have chosen to run a query for the following state: " +
                                  StateTextBox.Value;
          }
        break;
        
      default:
        
        // If the button clicked is not recognized, erase the message on the page. 
        Message.InnerHtml = "";
        
        break;
        
    }
    
  }
</script>

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

<head runat="server">
    <title>HtmlButton ValidationGroup Example</title>
</head>
<body>
    <form id="form1" runat="server">    
    
        <h3>HtmlButton ValidationGroup Example</h3>   
         
      <table border="1" cellpadding="10">
         <tr>
            <td>
               <b>Enter city to query.</b> <br />
               
               <input id="CityTextBox" 
                      type="Text"
                      runat="server"/>
                      
               <asp:RequiredFieldValidator 
                      ID="CityReqValidator"
                      ControlToValidate="CityTextBox" 
                      ValidationGroup="CityInfoGroup" 
                      ErrorMessage="Please enter a city."
                      Display="Dynamic"
                      EnableClientScript="False"
                      runat="server"/>
                    
            </td>
            <td valign="bottom">
            
               <button id="CityQueryButton"
                       causesvalidation="True" 
                       validationgroup="CityInfoGroup" 
                       onserverclick="SubmitButton_Click"
                       runat="server">
                       Submit
               </button>
               
            </td>
         </tr>

         <tr>
            <td>
               <b>Enter state to query.</b> <br />
               
               <input id="StateTextBox" 
                      type="Text" 
                      runat="server"/>
               <asp:RequiredFieldValidator 
                      ID="StateReqValidator"
                      ControlToValidate="StateTextBox" 
                      ValidationGroup="StateInfoGroup"
                      ErrorMessage="Please enter a state."
                      Display="Dynamic"
                      EnableClientScript="False"
                      runat="server"/>
                      
            </td>
            <td valign="bottom">
            
               <button id="StateQueryButton"
                       causesvalidation="True"
                       validationgroup="StateInfoGroup"
                       onserverclick="SubmitButton_Click"
                       runat="server">
                       Submit
               </button>
               
            </td>
         </tr>

      </table>

      <br /><br />

      <span id="Message"
            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">
<script runat="server">
  Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    
    ' Determine which button was clicked.
    Select Case (CType(sender, HtmlButton)).ID
      
      Case "CityQueryButton"
        
                If (CityReqValidator.IsValid) Then
                    ' Indicate that the city query was selected.
                    Message.InnerHtml = "You have chosen to run a query for the following city: " & _
                                        CityTextBox.Value
                End If
                
            Case "StateQueryButton"
        
                If (StateReqValidator.IsValid) Then
                    ' Indicate that the state query was selected.
                    Message.InnerHtml = "You have chosen to run a query for the following state: " & _
                                        StateTextBox.Value
                End If
                
            Case Else
        
                ' If the button clicked is not recognized, erase the message on the page.
                Message.InnerHtml = ""
        
        
        End Select
    
  End Sub
</script>

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

<head runat="server">
    <title> HtmlButton CausesValidation Example </title>
</head>
<body>

    <form id="form1" runat="server">

      <h3> HtmlButton CausesValidation Example </h3>

      <table border="1" cellpadding="10">
         <tr>
            <td>
            
               <b>Enter city to query.</b> <br />
            
               <input id="CityTextBox" 
                      type="Text"
                      runat="server"/>
            
               <asp:RequiredFieldValidator 
                      ID="CityReqValidator"
                      ControlToValidate="CityTextBox"
                      ValidationGroup="CityInfoGroup"
                      ErrorMessage="Please enter a city."
                      Display="Dynamic"
                      EnableClientScript="False"
                      runat="server"/>
            </td>
            <td valign="bottom">
            
               <button id="CityQueryButton"
                       causesvalidation="True" 
                       validationgroup="CityInfoGroup"
                       onserverclick="SubmitButton_Click"
                       runat="server">
                       Submit
               </button>
               
            </td>
         </tr>

         <tr>
            <td>
               
               <b>Enter state to query.</b> <br />
               
               <input id="StateTextBox" 
                      type="Text" 
                      runat="server"/>
                      
               <asp:RequiredFieldValidator 
                      ID="StateReqValidator"
                      ControlToValidate="StateTextBox" 
                      ValidationGroup="StateInfoGroup"
                      ErrorMessage="Please enter a state."
                      Display="Dynamic"
                      EnableClientScript="False"
                      runat="server"/>
                      
            </td>
            <td valign="bottom">
            
               <button id="StateQueryButton"
                       causesvalidation="True"
                       validationgroup="StateInfoGroup"
                       onserverclick="SubmitButton_Click"
                       runat="server">
                       Submit
               </button>
               
            </td>
         </tr>

      </table>

      <br /><br />

      <span id="Message"
            runat="Server"/>
    </form>
    
</body>

</html>

설명

유효성 검사 그룹을 사용 하면 페이지에 유효성 검사 컨트롤 특정 범주에 할당할 수 있습니다. 각 유효성 검사 그룹 페이지의 다른 유효성 검사 그룹의 독립적으로 확인할 수 있습니다. 이 ValidationGroup 속성을 사용하여 컨트롤이 서버에 다시 게시할 때 유효성 검사를 수행할 유효성 검사 그룹의 HtmlButton 이름을 지정합니다.

이 속성은 속성 값 CausesValidation 이 .로 설정된 경우에만 적용됩니다 true. 속성 값을 ValidationGroup 지정하면 컨트롤이 서버에 다시 게시될 때 HtmlButton 지정된 그룹의 일부인 유효성 검사 컨트롤만 유효성이 검사됩니다. 이 속성 CausesValidation 에 대 한 값을 지정 하지 않고 속성으로 설정 true된 경우 유효성 검사 그룹에 할당 되지 않은 페이지의 모든 유효성 검사 컨트롤 유효성 검사 컨트롤은 컨트롤이 서버에 다시 게시 될 때 유효성이 검사 됩니다.

적용 대상

추가 정보