BaseValidator.EnableClientScript Proprietà

Definizione

Ottiene o imposta un valore che indica se la convalida sul client è abilitata.

public:
 property bool EnableClientScript { bool get(); void set(bool value); };
public bool EnableClientScript { get; set; }
[System.Web.UI.Themeable(false)]
public bool EnableClientScript { get; set; }
member this.EnableClientScript : bool with get, set
[<System.Web.UI.Themeable(false)>]
member this.EnableClientScript : bool with get, set
Public Property EnableClientScript As Boolean

Valore della proprietà

Boolean

true se la convalida sul client è abilitata; in caso contrario, false. Il valore predefinito è true.

Attributi

Esempio

Nell'esempio di codice seguente viene illustrato come usare la proprietà per disabilitare la EnableClientScript convalida lato client in modo che i numeri casuali possano essere generati nel server.

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 Button_Click(Object sender, EventArgs e) 
  {
    if (Page.IsValid)
    {
      MessageLabel.Text = "Page submitted successfully.";
    }
    else
    {
      MessageLabel.Text = "There is an error on the page.";
    }
  }
 
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Validator Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>Validator Example</h3>
     
      Enter a number from 1 to 10.
      <asp:textbox id="NumberTextBox" 
        runat="server"/>

      <asp:rangevalidator id="NumberCompareValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"  
        type="Integer"
        display="Dynamic" 
        errormessage="Please enter a value from 1 to 10."
        maximumvalue="10"
        minimumvalue="1"  
        text="*"
        runat="server"/>

      <asp:requiredfieldvalidator id="TextBoxRequiredValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"
        display="Dynamic" 
        errormessage="Please enter a value."
        text="*"
        runat="server"/>

      <br /><br />

      <asp:button id="SubmitButton"
        text="Submit"
        onclick="Button_Click"
        runat="server"/>
 
      <br /><br />
       
      <asp:label id="MessageLabel" 
        runat="server"/>

      <br /><br />

      <asp:validationsummary
        id="ErrorSummary"
        runat="server"/>
 
    </form>
  </body>
</html>
<%@ Page Language="VB" AutoEventWireup="False" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
  Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitButton.Click
 
    If Page.IsValid Then
    
      MessageLabel.Text = "Page submitted successfully."
    
    Else
    
      MessageLabel.Text = "There is an error on the page."
    
    End If
    
  End Sub
 
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Validator Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>Validator Example</h3>
     
      Enter a number from 1 to 10.
      <asp:textbox id="NumberTextBox" 
        runat="server"/>

      <asp:rangevalidator id="NumberCompareValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"  
        type="Integer"
        display="Dynamic" 
        errormessage="Please enter a value from 1 to 10."
        maximumvalue="10"
        minimumvalue="1"  
        text="*"
        runat="server"/>

      <asp:requiredfieldvalidator id="TextBoxRequiredValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"
        display="Dynamic" 
        errormessage="Please enter a value."
        text="*"
        runat="server"/>

      <br /><br />

      <asp:button id="SubmitButton"
        text="Submit"
        runat="server"/>
 
      <br /><br />
       
      <asp:label id="MessageLabel" 
        runat="server"/>

      <br /><br />

      <asp:validationsummary
        id="ErrorSummary"
        runat="server"/>
 
    </form>
  </body>
</html>

Commenti

Utilizzare la proprietà per specificare se la EnableClientScript convalida lato client è abilitata.

I controlli di convalida eseguono sempre la convalida nel server. Hanno anche un'implementazione completa sul lato client che consente ai browser supportati da DHTML (ad esempio Microsoft Internet Explorer 4.0 e versioni successive) di eseguire la convalida nel client. La convalida lato client migliora il processo di convalida controllando l'input utente prima che venga inviato al server. Ciò consente di rilevare errori nel client prima dell'invio del modulo, evitando il round trip delle informazioni necessarie per la convalida lato server.

Per impostazione predefinita, questo valore è impostato su true, che consente la convalida lato client se il browser lo supporta. È possibile disabilitare la convalida lato client in base al controllo. Questo è utile se l'aggiornamento dinamico nel client crea problemi con il layout della pagina o se si vuole eseguire un codice server prima che venga eseguita la convalida.

Questa proprietà non può essere impostata da temi oppure temi di fogli di stile. Per altre informazioni, vedere ThemeableAttribute e ASP.NET Temi e skin.

Si applica a

Vedi anche