Sunday, August 19, 2007

validation class

*The validation control classes are in the System.Web.UI.WebControls namespace. All of the controls inherit from the BaseValidator class. The base class includes the following properties:* ControlToValidate--The ID of the control that the validator will check. * ErrorMessage--Error message returned if validation fails. * Text--Message that is displayed in the validation control when validation fails. If a validation summary control is used, the ErrorMessage property should be set. * Display--If this property is set to Dynamic, then space will be created for the error message. If it's set to static, space will be reserved in advance incase there is an error and a message needs to be displayed. * IsValid--Boolean value that returns true if no validation error occurred. The page object also has its own IsValid property that will return true if no validation errors occurred on the entire page. You can check this property on the server to ensure that valid data was entered. However, you typically will only check the property if you manually initiate validation on the server by using the Page.Validate method unless you're concerned that validation isn't performed on the client due to the user turning off JavaScript or their browser doesn't support DHTML. * Enabled--If set to false, validation won't occur. * Validation Group -- Indicates which group the validation control is part of. * EnableClientSideScript--If set to True, browsers that support DHTML and JavaScript will have code generated that will validate on the client side. The same error messages will be displayed even though the page is being validated on the client. Keep in mind, that once the page is submitted to the server, the data will be validated again because users can circumvent client side code by saving it, doctoring it, and viewing it again locally. * You can format the error messages that are displayed by including HTML in the values you assign to the ErrorMessage and Text properties. * The image below shows why you might want to set both the ErrorMessage and the Text. Since both the validation control and the summary are displayed, two different text strings can be displayed. The error message is displayed in the validation control, while the text message is displayed in the validation summary.

No comments: