Presentation is loading. Please wait.

Presentation is loading. Please wait.

ASP.NET Validating user input Validating user input on the client and/or server side 1ASP.NET Validating User Input.

Similar presentations


Presentation on theme: "ASP.NET Validating user input Validating user input on the client and/or server side 1ASP.NET Validating User Input."— Presentation transcript:

1 ASP.NET Validating user input Validating user input on the client and/or server side 1ASP.NET Validating User Input

2 Validation Goals –Check validity of data from the end user How –Check user input on the client side or on the server side Examples –Is the name TextBox empty? –Does the email TextBox contain a structurally valid email address? 2ASP.NET Validating User Input

3 Client-side vs. server-side validation Client-side validation –Done in the browser –Uses JavaScript Users can disable JavaScript! Different browsers → different JavaScript versions –Does not require HTTP request + response Server-side validation –Done on the server –Uses C# –Requires HTTP request + response 3ASP.NET Validating User Input

4 Client-side and server-side validation Best practice –Client-side validation and server-side validation –Client-side saves time No HTTP request/response –Server-side Provides security –JavaScript not disable 4ASP.NET Validating User Input

5 ASP.NET Validation server controls ASP.NET performs browser detection –Client supports JavaScript Use client-side validation + server-side validation –Client does not support JavaScript Use server-side validation 5ASP.NET Validating User Input

6 The standard validation controls RequiredFieldValidator –Input field cannot be empty CompareValidator –Compare between user inputs using =, >, etc. RangeValidator –Minimum < input < maximum RegularExpressionValidator –Check the entry matches a pattern defined by the regular expression CustomValidator –Make your own validator DynamicValidator –Advanced: Exceptions thrown from the model ValidationSummary –Displays all error messages from validators in one spot Third-party controls –Not made by Microsoft or by you –Examples: www.peterblum.com/DESwww.peterblum.com/DES 6ASP.NET Validating User Input

7 Some properties common to all validation controls ControlToValidate –The control to be validated ErrorMessage –The message used in the ValidationSummary Text –The error message used in the validation control CssClass –Style appearance of the messages Example: aspnet/validation/Validation 7ASP.NET Validating User Input

8 Making validation happen – or not Validation happens because of an event –Example: button click event –Can be turned of (for some buttons in a form) Client-side validation can be turned off –Only server-side validation in effect – 8ASP.NET Validating User Input

9 References Bill Evjen et al. Professional ASP.NET 4 in C# and VB, Wrox 2010 –Chapter 4, Validation Server Controls, page 157-185 W3schools.com Validation Server Controls –http://w3schools.com/aspnet/aspnet_refvalida tioncontrols.asphttp://w3schools.com/aspnet/aspnet_refvalida tioncontrols.asp 9ASP.NET Validating User Input


Download ppt "ASP.NET Validating user input Validating user input on the client and/or server side 1ASP.NET Validating User Input."

Similar presentations


Ads by Google