简体   繁体   中英

How do I validate a form without JavaScript?

Im using regular asp.net c# (webforms)

i need to build a simple form that has some simple validation. i need to ensure that the form works correctly even if javascripts is disabled. will Page.IsValid be sufficient for this, or is there anything else i may have to consider?

thanks

客户端验证是可选的,服务器端验证是必需的。

Use the default ASP.NET validators in conjunction with Page.IsValid. They validate both client-side and server-side.

If Javascript is disabled, they'll still validate server-side.

Form validation is the process of confirming that the data that a user enters into a form field fulfils one or more rules that you have defined.

Currently, the only way to do this is with an imperative language such as JavaScript on the client side, or some other language (eg c#) on the server side. Future versions of HTML may include options for declarative solutions... but don't worry about that.

If JavaScript is disabled on the client side, then the only option is to do server side validation. This means that the contents of the form are submitted to the server; if validation fails, the server would respond with the original form, preferably with the user's content in place and an indication of what failed.

Server side validation can work as a graceful degradation. Implement server side validation first, then add client side validation as a layer on top of that.

只要您在页面上具有必要的验证控件,那么即使在客户端上关闭了javascript,ASP.Net也应该对数据进行服务器端验证并返回错误。

如果表单中的任何内容有特殊要求,例如验证字段不为空或验证电子邮件地址看起来像电子邮件地址,也可以考虑使用<asp:RequiredFieldValidator> (及相关标签 )。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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