Share via


PostBackOptions.ValidationGroup 속성

정의

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

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

속성 값

String

서버에 포스트백될 때 PostBackOptions 개체가 유효성 검사를 수행할 컨트롤 그룹입니다. 기본값은 빈 문자열("")입니다.

예제

다음 코드 예제는 ValidationGroupPerformValidation 두 되도록 속성 TextBox 컨트롤의 포스트백 이벤트가 생성 되기 전에에 입력 한 정보가 있습니다. NameTextBoxAgeTextBox 컨트롤의 일부인 합니다 PersonalInfoGroup 유효성 검사 그룹에 있지만 StateTextBox 컨트롤이 아닙니다. 따라서 사용자는에 데이터를 입력할 필요가 없습니다를 StateTextBox 포스트백 이벤트가 생성 되기 전에 제어 합니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

<%@ 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_Init(object sender, EventArgs e)
  {
    PostBackOptions myPostBackOptions = new PostBackOptions(FruitRadioButtonList);

    myPostBackOptions.RequiresJavaScriptProtocol = true;
    myPostBackOptions.PerformValidation = true;
    myPostBackOptions.ValidationGroup = "PersonalInfoGroup";

    string reference = Page.ClientScript.GetPostBackEventReference(myPostBackOptions);
    FruitRadioButtonList.Attributes.Add("onclick", reference);
  } 

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>PerformValidation and ValidationGroup Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <h3>PostBackOptions PerformValidation and 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 />
      
      <asp:label id="State" 
        text="Enter the state where you live:"
        runat="server"
        AssociatedControlID="StateTextBox">
      </asp:label>

      &nbsp
      
      <asp:textbox id="StateTextBox" 
        runat="server">
      </asp:textbox>

      &nbsp
      
      <br /><br />
    
    
      <asp:Label id="FruitLabel" 
        text="Please select your preferred fruit:" 
        runat="server"
        AssociatedControlID="FruitRadioButtonList">
      </asp:Label>
      
      <asp:RadioButtonList ID="FruitRadioButtonList" runat="server" >
        <asp:ListItem>Apples</asp:ListItem>
        <asp:ListItem>Oranges</asp:ListItem>
        <asp:ListItem>Pears</asp:ListItem>
        <asp:ListItem>Peaches</asp:ListItem>
        <asp:ListItem>Grapes</asp:ListItem>
        <asp:ListItem>Lemons</asp:ListItem>
        <asp:ListItem>Limes</asp:ListItem>
        <asp:ListItem>Plums</asp:ListItem>
      </asp:RadioButtonList>
      
    </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_Init(ByVal sender As Object, ByVal e As EventArgs)
  
    Dim myPostBackOptions As PostBackOptions = New PostBackOptions(FruitRadioButtonList)

    myPostBackOptions.RequiresJavaScriptProtocol = True
    myPostBackOptions.PerformValidation = True
    myPostBackOptions.ValidationGroup = "PersonalInfoGroup"

    Dim reference As String = Page.ClientScript.GetPostBackEventReference(myPostBackOptions)
    FruitRadioButtonList.Attributes.Add("onclick", reference)
    
  End Sub


</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>PerformValidation and ValidationGroup Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <h3>PostBackOptions PerformValidation and 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 />
      
      <asp:label id="State" 
        text="Enter the state where you live:"
        runat="server"
        AssociatedControlID="State">
      </asp:label>

      &nbsp
      
      <asp:textbox id="StateTextBox" 
        runat="server">
      </asp:textbox>

      &nbsp
      
      <br /><br />
    
    
      <asp:Label id="FruitLabel" 
        text="Please select your preferred fruit:" 
        runat="server"
        AssociatedControlID="FruitRadioButtonList">
      </asp:Label>
      
      <asp:RadioButtonList ID="FruitRadioButtonList" runat="server" >
        <asp:ListItem>Apples</asp:ListItem>
        <asp:ListItem>Oranges</asp:ListItem>
        <asp:ListItem>Pears</asp:ListItem>
        <asp:ListItem>Peaches</asp:ListItem>
        <asp:ListItem>Grapes</asp:ListItem>
        <asp:ListItem>Lemons</asp:ListItem>
        <asp:ListItem>Limes</asp:ListItem>
        <asp:ListItem>Plums</asp:ListItem>
      </asp:RadioButtonList>
      
    </form>
  </body>
</html>

설명

사용 된 ValidationGroup 포스트백 이벤트가 생성 될 때 유효성을 검사 하려면 유효성 검사 그룹을 지정 하는 속성입니다. 지정 된 유효성 검사 그룹의 유효성 검사 컨트롤에만 유효성이 검사 됩니다.

적용 대상

추가 정보