PostBackOptions.PerformValidation Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece un valor que indica si se requiere la validación del lado cliente antes de que se produzca el evento postback.
public:
property bool PerformValidation { bool get(); void set(bool value); };
public bool PerformValidation { get; set; }
member this.PerformValidation : bool with get, set
Public Property PerformValidation As Boolean
Valor de propiedad
true si se requiere la validación del lado cliente antes de que se produzca el evento de postback; de lo contrario, false. El valor predeterminado es false.
Ejemplos
En el ejemplo de código siguiente se muestra el uso de las ValidationGroup propiedades y PerformValidation para asegurarse de que dos TextBox controles tienen información especificada en ellos antes de que se genere el evento postback. Los NameTextBox controles y AgeTextBox forman parte del PersonalInfoGroup grupo de validación, pero el StateTextBox control no lo es. Por lo tanto, el usuario no tiene que escribir ningún dato en el StateTextBox control antes de que se genere el evento postback.
Importante
Este ejemplo tiene un cuadro de texto que acepta la entrada del usuario, que es una amenaza de seguridad potencial. De forma predeterminada, ASP.NET páginas web validan que la entrada del usuario no incluye elementos HTML ni de script. Para obtener más información, consulte Información general sobre vulnerabilidades de seguridad de script.
<%@ 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>
Comentarios
La PerformValidation propiedad se usa para especificar si se requiere la validación del lado cliente antes de que se pueda producir el evento de postback. Cuando el valor de la PerformValidation propiedad se establece trueen , también puede usar la ValidationGroup propiedad para especificar el nombre del grupo de validación para el que se requiere la validación antes de que se produzca el evento postback.