Sunday, January 25, 2009

Client-Side vs. Server-Side Validation

If the browser supports DHTML, ASP.NET validation controls can perform validation by using client script . The advantage of using client script is that a feedback can be provided without a response from the server . The validation controls automatically detect whether the browser supports DHTML and perform the validation accordingly.

The error display mechanism for client side is same as server-side validation. Validation is performed on the server even if it was already performed on the client. This enables you to determine the validation status in the server code and ensure security against users bypassing client-side validation.

If validation is performed on the client, validation controls include some additional features:
  • If you are summarizing validation error messages, you can display them in a message box that appears when the user submits the page.
  • Validation controls present the same object model on the client as on the server. For example, you can test validation by reading a validation control's IsValid property the same way, on both the client and the server. However, there are differences in the validation information exposed at the page level. On the server, the page supports properties; on the client, it contains global variables.
  1. Client : Page_IsValid
    Server : IsValid
  2. Client : Page_Validators (array). Contains references to all validation controls on te page. Server: Validators (collection). Contains references to all validation controls.
  3. Client : Page_ValidationActive. A Boolean value that indicates whether validation should take place. Set this variable to false to turn off client-side validation programmatically.
    Server : Not applicable


Note : If client-side validation is enabled, the page includes references to script libraries that are used to perform the client-side validation.When you use a RegularExpressionValidator control, the expressions can be checked on the client if an ECMAScript-compatible language, such as Microsoft JScript is available. Client-side regular expressions differ in small details from the regular expression checking done on the server by using the Regex class.The page includes a client-side method to intercept and handle the Click event before the page is submitted.

Source of Reference : MSDN

No comments:

 
Google