다음을 통해 공유


HtmlInputImage.ValidationGroup 속성

정의

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

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

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

예제

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


<%@ Page Language="C#" AutoEventWireup="True" %>

<!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, ImageClickEventArgs e)
  {

    // Determine which button was clicked.
    switch (((HtmlInputImage)sender).ID)
    {

      case "CityQueryButton":

        // Take the appropriate action if the controls pass validation. 
        if (CityReqValidator.IsValid)
        {
          Message.InnerHtml = "You have chosen to run a query for the following city: " +
             CityTextBox.Value;
        }

        break;

      case "StateQueryButton":

        // Take the appropriate action if the controls pass validation.
        if (StateReqValidator.IsValid)
        {
          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>
    <title> HtmlInputImage CausesValidation Example </title>
</head>

<body>

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

      <h3> HtmlInputImage 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="<br />Please enter a city."
                      Display="Dynamic"
                      EnableClientScript="False"
                      runat="server"/>
            </td>
            <td valign="bottom">
               <input id="CityQueryButton"
                      alt="City Submit button"
                      type="Image"
                      src="Image.jpg"
                      causesvalidation="true"
                      validationgroup="CityInfoGroup"
                      onserverclick="SubmitButton_Click"
                      runat="server"/>
            </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="<br />Please enter a state."
                      Display="Dynamic"
                      EnableClientScript="False"
                      runat="server"/>
            </td>
            <td valign="bottom">
               <input id="StateQueryButton"
                      alt="State Submit button"
                      type="Image"
                      src="Image.jpg"
                      causesvalidation="True"
                      validationgroup="StateInfoGroup"
                      onserverclick="SubmitButton_Click"
                      runat="server"/>
            </td>
         </tr>

      </table>

      <br /><br />

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

   </form>

</body>
</html>

<%@ Page Language="VB" AutoEventWireup="True" %>

<!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 ImageClickEventArgs)
         
    ' Determine which button was clicked.
    Select Case (CType(sender, HtmlInputImage)).ID

      Case "CityQueryButton"

        ' Take the appropriate action if the controls pass validation. 
        If CityReqValidator.IsValid Then
           
          Message.InnerHtml = "You have chosen to run a query for the following city: " & _
             CityTextBox.Value
               
        End If

      Case "StateQueryButton"

        ' Take the appropriate action if the controls pass validation.
        If StateReqValidator.IsValid Then
               
          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>
    <title> HtmlInputImage CausesValidation Example </title>
</head>

<body>

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

      <h3> HtmlInputImage 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="<br />Please enter a city."
                      Display="Dynamic"
                      EnableClientScript="False"
                      runat="server"/>
            </td>
            <td valign="bottom">
               <input id="CityQueryButton"
                      alt="City Submit button"
                      type="Image"
                      src="Image.jpg"
                      causesvalidation="True"
                      validationgroup="CityInfoGroup"
                      onserverclick="SubmitButton_Click"
                      runat="server"/>
            </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="<br />Please enter a state."
                      Display="Dynamic"
                      EnableClientScript="False"
                      runat="server"/>
            </td>
            <td valign="bottom">
               <input id="StateQueryButton"
                      alt="State Submit button"
                      type="Image"
                      src="Image.jpg"
                      causesvalidation="True"
                      validationgroup="StateInfoGroup"
                      onserverclick="SubmitButton_Click"
                      runat="server"/>
            </td>
         </tr>

      </table>

      <br /><br />

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


   </form>

</body>
</html>

설명

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

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

적용 대상

추가 정보