ASP.NET中的验证控件是在服务器端还是在客户端运行? [英] Validation controls in ASP.NET are run at server- or client-side?
问题描述
我正在创建一个ASP.NET应用程序,我想知道ASP.NET上的验证控件在哪里运行?在服务器还是客户端计算机上?
I'm creating an ASP.NET application and I want to know where are the validation controls on ASP.NET run? On server or on client machine?
我是否应该考虑使用JavaScript对项目执行简单的表单验证?
Should I consider using JavaScript to perform simple form validations to my project instead?
推荐答案
自ASP.NET 2.0以来的所有操作都将在页面上运行服务器端检查,以通过检查任何验证程序控件(在服务器端运行)来确保它是有效的与后面代码中Form_Load属性中的.IsValid()一起使用.此过程需要回发到服务器,这意味着,如果他们错过了一些简单的事情(例如填写姓名字段),则必须先提交表单,但这种表单性能不佳,有时价格昂贵.
Anything since around ASP.NET 2.0 will run a server side check on the page to make sure it is valid by checking any validator controls (which runs server side) with the .IsValid() in the Form_Load property in the code behind. This process requires a postback to the server which means that if they missed something simple like filling in a name field that they had to submit the form first which is not performant and sometimes expensive.
在名为"EnableClientScript"的控件上有一个验证器属性,该属性将运行javascript函数来验证诸如缺少字段信息之类的简单内容,甚至对电话号码或电子邮件地址之类的内容进行正则检查.
There is a validator property on the controls entitled 'EnableClientScript' which will run a javascript function to verify simple things like missing field information or even reg ex checks on things like phone number or e-mail address.
David还是要验证此输入的说法也是正确的.最好的策略是针对任何无意或恶意的尝试进行防御性编码,尤其是当您拥有面向公众的网站时.
David is also correct that you want to verify this input anyway. The best policy is to defensively code against any unintentional or malicious attempts especially if you have a public facing site.
这篇关于ASP.NET中的验证控件是在服务器端还是在客户端运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!