PostBackOptions.ValidationGroup Propriedade
Definição
Obtém ou define o grupo de controles para o qual o objeto PostBackOptions causa a validação quando ele executa um postback para o servidor.Gets or sets the group of controls for which the PostBackOptions object causes validation when it posts back to the server.
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
Valor da propriedade
O grupo de controles para o qual o PostBackOptions objeto causa validação quando é Postado de volta ao servidor.The group of controls for which the PostBackOptions object causes validation when it posts back to the server. O valor padrão é uma cadeia de caracteres vazia ("").The default value is an empty string ("").
Exemplos
O exemplo de código a seguir demonstra ValidationGroup como usar as PerformValidation Propriedades e para garantir que dois TextBox controles tenham informações inseridas antes de o evento de postback ser gerado.The following code example demonstrates using the ValidationGroup and PerformValidation properties to ensure that two TextBox controls have information entered in them before the postback event is generated. Os NameTextBox AgeTextBox controles e fazem parte do PersonalInfoGroup grupo de validação, mas o StateTextBox controle não é.The NameTextBox and AgeTextBox controls are part of the PersonalInfoGroup validation group, but the StateTextBox control is not. Portanto, o usuário não precisa inserir nenhum dado no StateTextBox controle antes que o evento de postback seja gerado.Therefore, the user does not have to enter any data in the StateTextBox control before the postback event is generated.
Importante
Este exemplo tem uma caixa de texto que aceita a entrada do usuário, que é uma possível ameaça à segurança.This example has a text box that accepts user input, which is a potential security threat. Por padrão, as páginas da Web do ASP.NET validam que a entrada do usuário não inclui elementos de script ou HTML.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Para obter mais informações, consulte Visão geral de explorações de script.For more information, see 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>
 
<asp:textbox id="NameTextBox"
runat="server">
</asp:textbox>
 
<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>
 
<asp:textbox id="AgeTextBox"
runat="server">
</asp:textbox>
 
<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>
 
<asp:textbox id="StateTextBox"
runat="server">
</asp:textbox>
 
<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>
 
<asp:textbox id="NameTextBox"
runat="server">
</asp:textbox>
 
<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>
 
<asp:textbox id="AgeTextBox"
runat="server">
</asp:textbox>
 
<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>
 
<asp:textbox id="StateTextBox"
runat="server">
</asp:textbox>
 
<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>
Comentários
Use a ValidationGroup propriedade para especificar o grupo de validação a ser validado quando um evento de postback for gerado.Use the ValidationGroup property to specify the validation group to validate when a postback event is generated. Somente os controles de validação no grupo de validação especificado são validados.Only the validation controls in the specified validation group are validated.