- Community Pick
- Experts Exchange Approved
The above code has a dropdown control with an ASP.NET required field validator control, and a validator callout control attached to it. As soon as you click the submit button, and there is a validation error, the error will be popped out in the validator callout control, as shown below.
The popping of error message in a validator callout control happens automatically. But there may be scenario where you would like to hide or show the validator control using Javascript. The below sample code does exactly that:
In the above code, there is a line like this:
“AjaxControlToolkit.Valida
The _currentCallout property will hold a reference to a ValidatorCalloutExtender (VCE) control. Whenever there is a validation failure, and there is a validator callout control associated with a validation control, the _currentCallout property will hold a reference to that VCE. If there are more than one VCE controls on the page, then the VCE control associated with the first validation control which throws the error will be assigned to the "_currentCallout" property. To hide the validator callout control, you need to use the “hide” Javascript function, along with the _currentCallout property, as shown below:
At any given point the _currentCallout property will have only one VCE assigned, this is to avoid the confusion or dirtiness which can arise by displaying all the VCE control at the same time. If all the validator callouts are shown, when multiple validation fails, then the screen will be cluttered with lots of VCE controls popping here and there. To avoid cluttered view this approach of showing only one VCE control at a time has been taken.
Similarly, to show the validator callout control, you can use the “show” Javascript method, along with the _currentCallout property, as shown below:
But, the above code, if used just like that, can throw the following error:
Microsoft JScript runtime error: 'this._popupBehavior' is null or not an object
The reason why this happens is that we have not called either ValidatorEnable or ValidatorValidate Javascript functions. These two functions set the necessary things, like _popupBehavior property, for the validator control to work properly. VCE controls are not meant to be shown directly--they are actually extender controls, which extend the functionality of the validation control. These controls are shown automatically when a validatation control's validation condition fails. If you want to show a VCE function, call the ValidatorEnable or ValidatorValidate Javascript function.
That's about it on how to hide and show validator callout controls using Javascript. I know I have not mentioned anything about the “$find” javascript function. You can find more about $find in one of my blogs here.
Some important methods of ValidatorCallout controls:
_getErrorMessage(): Gets/returns the error message
get_closeImageUrl(): Gets/returns the close image url at the top rightmost corner of the validator callout control--default is an x mark
get_isOpen(): Gets/returns a boolean value indicating whether the validator callout is opened or not
get_warningIconImageUrl():
get_width(): Gets/returns the width of the validator callout control
hide(): Function to hide the validator callout control
set_closeImageUrl(imageUrl
set_warningIconImageUrl(im
set_width(int) Function used to set the width of the validator callout control
show(): To show the validator callout control
_closeImageUrl: Property to get/set the close image
_warningIconImageUrl: Property to get/set the warning image
_width: Property to get/set the width of the validator callout control
_popupBehavior: Property using which one can work with the pop up behaviour of the validator callout control
_errorMessageCell: Property using which one can modify the error message
Some methods of ValidatorCallout._popupBeh
Below I have listed few methods of _popupBehavior property of validator callout function. These methods are available with only _popupBehavior property. If you want to use these methods, then retrieve the _popupBehavior property from validator callout control by any of the following two means shown below:
After retrieving the _popupBehavior property with the above methods, you can use the following methods:
get_x(): Method to get the X coordinates of the validator callout control
get_y(): Method to get the Y coordinates of the validator callout control.
get_visible(): Methods that returns a boolean value specifying whether the validator callout control is visible or not.
set_x(x_coordinate): Method to set the X coordinate for the validator callout control. Method takes an integer value as an argument.
set_y(y_coordinate): Method to set the Y coordinate for the validator callout control. Method takes an integer value as an argument.
Some methods of ValidatorCallout._errorMes
Since _errorMessageCell returns a TD (cell) object, there is nothing much new. It has all the methods/properties corresponding to a cell object. You can use this property to change the error message of the validator callout extendor control using Javascript. To change the error message using Javascript, see the code below:
You can find the original article and discussions here (http://sandblogaspnet.blo
by: sand1980 on 2010-04-10 at 07:36:38ID: 12899
The grammatical corrections look great. I don't have anything to add to the article.
Regards,
Sandeep