BaseValidator.EnableClientScript Propriedade
Definição
Obtém ou define um valor que indica se a validação do lado do cliente está habilitada.Gets or sets a value indicating whether client-side validation is enabled.
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
Valor da propriedade
true se a validação do lado do cliente estiver habilitada; caso contrário, false.true if client-side validation is enabled; otherwise, false. O valor padrão é true.The default value is true.
- Atributos
Exemplos
O exemplo de código a seguir demonstra como usar a EnableClientScript propriedade para desabilitar a validação do lado do cliente para que os números aleatórios possam ser gerados no servidor.The following code example demonstrates how to use the EnableClientScript property to disable client-side validation so that the random numbers can be generated on the server.
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 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>
Comentários
Use a EnableClientScript propriedade para especificar se a validação do lado do cliente está habilitada.Use the EnableClientScript property to specify whether client-side validation is enabled.
Os controles de validação sempre executam a validação no servidor.Validation controls always perform validation on the server. Eles também têm uma implementação completa do lado do cliente que permite que os navegadores com suporte para DHTML (como o Microsoft Internet Explorer 4,0 e posterior) executem a validação no cliente.They also have complete client-side implementation that allows DHTML-supported browsers (such as Microsoft Internet Explorer 4.0 and later) to perform validation on the client. A validação no lado do cliente aprimora o processo de validação verificando a entrada do usuário antes de ser enviada ao servidor.Client-side validation enhances the validation process by checking user input before it is sent to the server. Isso permite que os erros sejam detectados no cliente antes que o formulário seja enviado, evitando a viagem de ida e volta das informações necessárias para a validação do lado do servidor.This allows errors to be detected on the client before the form is submitted, avoiding the round trip of information necessary for server-side validation.
Por padrão, esse valor é definido como true , que habilita a validação do lado do cliente se o navegador oferecer suporte a ela.By default, this value is set to true, which enables client-side validation if the browser supports it. Você pode desabilitar a validação do lado do cliente com base em controle por controle.You can disable client-side validation on a control-by-control basis. Isso será útil se a atualização dinâmica no cliente criar problemas com o layout da página ou se você quiser executar algum código de servidor antes que a validação ocorra.This is useful if dynamic updating on the client creates problems with the layout of the page, or if you want to execute some server code before validation takes place.
Esta propriedade não pode ser definida por temas ou temas de folha de estilo.This property cannot be set by themes or style sheet themes. Para obter mais informações, consulte ThemeableAttribute e temas e capas do ASP.net.For more information, see ThemeableAttribute and ASP.NET Themes and Skins.