PostBackOptions.PerformValidation Proprietà

Definizione

Ottiene o imposta un valore che indica se è necessaria la convalida del lato client prima dell'avvio dell'evento di 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

Valore della proprietà

Boolean

true se è necessaria la convalida sul lato client prima che venga avviato l'evento di postback; in caso contrario, false. Il valore predefinito è false.

Esempio

Nell'esempio di codice seguente viene illustrato l'uso delle ValidationGroup proprietà e PerformValidation per assicurarsi che due TextBox controlli dispongano di informazioni immesse prima che venga generato l'evento di postback. I NameTextBox controlli e AgeTextBox fanno parte del PersonalInfoGroup gruppo di convalida, ma il StateTextBox controllo non è . Pertanto, l'utente non deve immettere dati nel StateTextBox controllo prima che venga generato l'evento di postback.

Importante

L'esempio include una casella di testo che accetta l'input dell'utente e rappresenta quindi una potenziale minaccia alla sicurezza. Per impostazione predefinita, le pagine Web ASP.NET verificano che l'input dell'utente non includa script o elementi HTML. Per altre informazioni, vedere Cenni preliminari sugli attacchi tramite 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>

      &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>

Commenti

La PerformValidation proprietà viene utilizzata per specificare se è necessaria la convalida lato client prima che possa verificarsi l'evento di postback. Quando il valore della PerformValidation proprietà è impostato su true, è anche possibile utilizzare la ValidationGroup proprietà per specificare il nome del gruppo di convalida per cui è necessaria la convalida prima che si verifichi l'evento di postback.

Si applica a

Vedi anche