如何在 ASP.Net 的客户端(JavaScript)上检查 Page.Validate()?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3967161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 06:54:24  来源:igfitidea点击:

How to check Page.Validate() on client side (JavaScript) in ASP.Net?

javascriptasp.net.netvalidation

提问by Azhar

I want to check page validation on client side, like Page.Validate()but it's a server side method. Is there any client side function which can work like Page.Validate()with JavaScript?

我想在客户端检查页面验证,Page.Validate()但它是一种服务器端方法。是否有任何客户端功能可以像Page.Validate()JavaScript一样工作?

回答by Azhar

Page_ClientValidate()will work. It returns true if the page was valid and it works fine.

Page_ClientValidate()将工作。如果页面有效并且工作正常,则返回 true。

If you are using ASP.NET 2.0, pass the validation group name as a parameter.
E.g.

如果您使用的是 ASP.NET 2.0,请将验证组名称作为参数传递。
例如

if(Page_ClientValidate("SomeValidationGroup"))
     alert('its valid');

Otherwise if there is no validation group Page_ClientValidate("")will handle it.
E.g.

否则如果没有验证组Page_ClientValidate("")将处理它。
例如

if(Page_ClientValidate(""))
     alert('its valid');

回答by Tim Schmelter

There is a mini-clientside-validation API:

有一个迷你客户端验证 API:

http://msdn.microsoft.com/en-us/library/aa479045.aspx#aspplusvalid_clientside

http://msdn.microsoft.com/en-us/library/aa479045.aspx#aspplusvalid_clientside

alt text

替代文字

and here are some functions to trigger validation on validators:

以下是一些触发验证器验证的函数:

alt text

替代文字