简体   繁体   English

Asp.Net CustomValidator无法在Java脚本中生成相等的函数

[英]Asp.Net CustomValidator is not generating equal functions in java script

I am working on a registration page of my Asp.Net website. 我正在Asp.Net网站的注册页面上。 When we use Server side Asp.net built-in validation controls, they work both on client side (by generating appropriate java script code) and offer server side protection too. 当我们使用服务器端Asp.net内置验证控件时,它们既可以在客户端(通过生成适当的Java脚本代码)工作,也可以提供服务器端保护。 So if somebody circumvent that java script, still the page has to be validated on the server. 因此,如果有人绕过该Java脚本,则仍必须在服务器上验证该页面。 Currently i am using my own asp.net C# functions in Custom Validators to do the job but these only works on server side. 目前,我在Custom Validators中使用我自己的asp.net C#函数来完成这项工作,但是这些仅在服务器端有效。 I mean the equal java script is not automatically generated on my web form. 我的意思是相等的Java脚本不会在我的Web表单上自动生成。 Is it the default behavior of Asp.Net or am i missing anything? 它是Asp.Net的默认行为还是我错过了任何东西? Do I have to write my client side java script on myself when i use asp.net custom validators? 当我使用asp.net自定义验证器时,是否必须在自己的客户端上编写Java脚本?

My 2nd question is when we write function for our asp.net custom validator. 我的第二个问题是当我们为asp.net自定义验证器编写函数时。 They are called when the page is submitted to server. 当页面提交到服务器时,将调用它们。 can i access such function with java script, so that the will start working before the page is submitted to the server. 我可以使用Java脚本访问此类功能,以便在将页面提交到服务器之前开始工作。

For a custom validator you have to write your own validation code in both javascript and C# 对于自定义验证器,您必须同时使用javascript和C#编写自己的验证代码

If you attach some javascript to the validator it will fire along with all the standard .net validators on the page, so errors can get caught before postback 如果您将一些JavaScript附加到验证器,它将与页面上的所有标准.net验证器一起触发,因此在回发之前可能会捕获错误

You need to make sure the ClientValidationFunction method is set. 您需要确保设置了ClientValidationFunction方法。

<asp:CustomValidator 
     id="ProgrammaticID" 
     ControlToValidate="programmatic ID of Server Control to Validate"
     ClientValidationFunction="ClientValidateID"
     OnServerValidate="ServerValidateID"
     ErrorMessage="Message to display in ValidationSummary control"
     Text="Message to display in control" 
     ForeColor="value" 
     BackColor="value"  
     runat="server" >
</asp:CustomValidator>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM