views:

146

answers:

5

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

A: 

As long as you have the necessary validation controls on the page then even if javascript is turned off at the client, ASP.Net should do server side validation on the data and return an error.

Wil
A: 

Also consider using <asp:RequiredFieldValidator> (and related tags) if anything in the form has special requirements, such as verifying fields are not empty or verifying that an e-mail address looks like an email address.

Brian
+5  A: 

Client side validation is optional, server side validation is mandatory.

z-boss
You should always validate server-side, especially if information is going to a database.
Alex
+5  A: 

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.

Randolpho
I agree. I would however build an approach that tries for client-side if Javascript is available using these same controls as a default. It's always best to do some validation as close to the user as feasible.
Nissan Fan
@Nissan Fan: Oh, definitely. Validating client-side provides less round-trips to the server for validation, and an overall more usable experience. But remember, @sneg is 100% correct: you *must* validate server-side, even if you validate client-side.
Randolpho
+1: I actually had to show some of the senior developers where I work that ASP.NET validators still did server-side validation even if I disabled client-side scripting.
R. Bemrose
+1  A: 

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 (e.g. 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.

Dancrumb