Class TBaseValidator
TBaseValidator class
TBaseValidator serves as the base class for validator controls.
Validation is performed when a postback control, such as a TButton, a
TLinkButton or a TTextBox (under AutoPostBack mode) is submitting the page and
its CausesValidation property is true. You can also manually perform
validation by calling TPage::validate()
. The input control to be
validated is specified by setControlToValidate ControlToValidate.
Validator controls always validate the associated input control on the serve side. In addition, if getEnableClientScript EnableClientScript is true, validation will also be performed on the client-side using javascript. Client-side validation will validate user input before it is sent to the server. The form data will not be submitted if any error is detected. This avoids the round-trip of information necessary for server-side validation.
You can use multiple validator controls to validate a single input control,
each responsible for validating against a different criteria. For example, on a
user registration form, you may want to make sure the user enters a value in the
username text box, and the input must consist of only word characters. You can
use a TRequiredFieldValidator
to ensure the input of username and a
TRegularExpressionValidator
to ensure the proper input.
If an input control fails validation, the text specified by the setErrorMessage ErrorMessage property is displayed in the validation control. However, if the setText Text property is set, it will be displayed instead. If both setErrorMessage ErrorMessage and setText Text are empty, the body content of the validator will be displayed. Error display is controlled by setDisplay Display property.
You can also customized the client-side behaviour by adding javascript code to the subproperties of the getClientSide ClientSide property. See quickstart documentation for further details.
You can also place a TValidationSummary
control on a page to display
error messages from the validators together. In this case, only the setErrorMessage ErrorMessage property of the validators will be displayed in
the TValidationSummary
control.
Validators can be partitioned into validation groups by setting their setValidationGroup ValidationGroup property. If the control causing the validation also sets its ValidationGroup property, only those validators having the same ValidationGroup value will do input validation.
Note, the TPage::getIsValid IsValid property of the current TPage
instance will be automatically updated by the validation process which
occurs after TPage::onLoad onLoad of TPage
and before the
postback events. Therefore, if you use the TPage::getIsValid()
property
in the TControl::onLoad()
method, you must first explicitly call the TPage::validate()
method.
Notes to Inheritors When you inherit from TBaseValidator, you must
override the method TBaseValidator::evaluateIsValid()
.
- TComponent
-
TApplicationComponent
-
TControl implements IRenderable, IBindable
-
TWebControl implements IStyleable
-
TLabel implements IDataRenderer
-
TBaseValidator implements IValidator
Direct known subclasses
TCaptchaValidator, TCompareValidator, TCustomValidator, TDataTypeValidator, TListControlValidator, TRangeValidator, TReCaptchaValidator, TRegularExpressionValidator, TRequiredFieldValidatorPackage: System\Web\UI\WebControls
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Web/UI/WebControls/TBaseValidator.php
public
|
|
public
|
|
public
|
|
protected
|
#
addAttributesToRender(
Adds attributes to renderer. Calls parent implementation and renders the client control scripts. |
protected
array
|
|
public
|
#
getClientSide( )
Gets the TValidatorClientSide that allows modification of the client- side validator events. |
protected
|
|
public
|
#
renderClientControlScript(
Renders the javascript code to the end script. If you override this method, be sure to call the parent implementation so that the event handlers can be invoked. |
public
|
#
onPreRender(
Override parent implementation to update the control CSS Class before the validated control is rendered |
protected
boolean
|
#
updateControlCssClass( )
Update the ControlToValidate component's css class depending if the ControlCssClass property is set, and whether this is valid. |
protected
|
|
abstract protected
string
|
#
getClientClassName( )
Gets the name of the javascript class responsible for performing validation for this control. This method overrides the parent implementation. |
public
|
#
setForControl( string $value )
This method overrides the parent implementation to forbid setting ForControl. |
public
|
#
setEnabled( boolean $value )
This method overrides parent's implementation by setting setIsValid IsValid to true if disabled. |
public
|
|
public
|
|
public
boolean
|
|
public
|
|
public
string
|
|
public
|
|
public
string
|
|
public
|
#
setControlToValidate( string $value )
Sets the ID path of the input control to validate. The ID path is the dot-connected IDs of the controls reaching from the validator's naming container to the target control. |
public
boolean
|
|
public
|
|
public
string
|
#
getFocusElementID( )
Gets the ID of the HTML element that will receive focus if validation fails and getFocusOnError FocusOnError is true. Defaults to the client ID of the getControlToValidate ControlToValidate. |
public
|
#
setFocusElementID( string $value )
Sets the ID of the HTML element that will receive focus if validation fails and getFocusOnError FocusOnError is true. |
public
string
|
|
public
|
|
public
boolean
|
|
public
|
|
public
|
|
protected
string
|
|
public
boolean
|
#
validate( )
Validates the specified control. Do not override this method. Override |
public
string
|
|
public
|
|
abstract protected
boolean
|
#
evaluateIsValid( )
This is the major method for validation. Derived classes should implement this method to provide customized validation. |
public
|
|
public
|
|
public
|
#
onValidate( )
This event is raised right before the validator starts to perform validation. You may use this event to change the behavior of validation. For example, you may disable the validator if certain condition is satisfied. Note, the event will NOT be raised if the validator is invisible. |
public
|
getData(),
getForControl(),
getTagName(),
getText(),
render(),
setData(),
setText()
|
getApplication(),
getRequest(),
getResponse(),
getService(),
getSession(),
getUser(),
publishAsset(),
publishFilePath()
|
GLOBAL_RAISE_EVENT_LISTENER
|
$_decorator
|