System.Web
1.0.5000.0
2.0.0.0
Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details.
System.Web.UI.WebControls.BaseValidator
System.Web.UI.ToolboxData("<{0}:CustomValidator runat="server" ErrorMessage="CustomValidator"></{0}:CustomValidator>")
System.ComponentModel.DefaultEvent("ServerValidate")
Use the control to provide a user-defined validation function for an input control. The control is a separate control from the input control it validates, which allows you to control where the validation message is displayed.
Validation controls always perform validation on the server. They also have complete client-side implementation that allows script-enabled browsers (such as Microsoft Internet Explorer 4.0 and later) to perform validation on the client. Client-side validation enhances the validation process by checking user input before it is sent to the server. This allows errors to be detected on the client before the form is submitted, thus avoiding the round trip of information necessary for server-side validation.
To create a server-side validation function, provide a handler for the event that performs the validation. The string from the input control to validate can be accessed by using the property of the object passed into the event handler as a parameter. The result of the validation is then stored in the property of the object.
To create a client-side validation function, first add the server-side validation function described earlier. Next, add the client-side validation script function to the ASP.NET (.aspx) page.
If you are using Visual Basic Scripting Edition (VBScript), the function must be in this form:
Sub ValidationFunctionName(source, arguments)
If you are using JScript, the function must be in this form:
function ValidationFunctionName(source, arguments)
The parameter is a reference to the <span> element rendered for the control. This allows you to programmatically control the <span> tag, such as modifying the attribute. The parameter is an object with two properties: Value and IsValid. This parameter allows you to get the value of the control to validate and to indicate whether the value is valid based on your custom validation routine.
Use the property to specify the name of the client-side validation script function associated with the control. Because the script function is executed on the client, the function must be in a language that the target browser supports, such as VBScript or JScript.
When you use the control inside an control, make sure that the validator control and the control it is associated with are in the same panel. For more information about using the control for partial-page updates, see Partial-Page Rendering Overview.
Like server-side validation, the string from the input control to validate is accessed by using the property of the parameter. Return the result of the validation by setting the property of the parameter.
When using validator controls, you should always check the results of server-side validation before performing any processing. After a postback but before your event methods are called, the page calls the validator controls and aggregates their results into the property. (You can also call the validator controls explicitly using the Validate method.) In your own code, you should check that the property returns true before processing input. Even though script-enabled browsers might prevent a postback from occurring on the client if a validation check has failed, you should always also check in server code before processing validated data.
Multiple validation controls can be used with an individual input control to validate different criteria. For example, you can apply multiple validation controls on a control that allows the user to enter the quantity of items to add to a shopping cart. You can use a control to ensure that the value specified is less than the amount in inventory and a control to ensure that the user enters a value into the control.
If the input control is empty, no validation functions are called and validation succeeds. Use a control to require the user to enter data in the input control.
It is possible to use a control without setting the property. This is commonly done when you are validating multiple input controls or validating input controls that cannot be used with validation controls, such as the control. In this case, the property of the parameter passed to the event handler for the event and to the client-side validation function always contains an empty string (""). However, these validation functions are still called, where appropriate, to determine validity on both the server and client. To access the value to validate, you must programmatically reference the input control you want to validate and then retrieve the value from the appropriate property. For example, to validate a control on the server, do not set the property of the validation control and use the following code for the handler for the event.
Sub ServerValidation (source As object, args As ServerValidateEventArgs)
args.IsValid = (CheckBox1.Checked = True)
End Sub
void ServerValidation (object source, ServerValidateEventArgs args)
{
args.IsValid = (CheckBox1.Checked == true);
}
For more information on validation controls, see .
Accessibility
For information about how to configure this control so that it generates markup that conforms to accessibility standards, see Accessibility in Visual Studio 2010 and ASP.NET 4 and ASP.NET Controls and Accessibility.
Performs user-defined validation on an input control.
Constructor
To be added
Initializes a new instance of the class.
1.0.5000.0
2.0.0.0
Method
System.Void
To be added
Adds the properties of the control to the output stream for rendering on the client.
A that contains the output stream for rendering on the client.
1.0.5000.0
2.0.0.0
Property
System.String
To be added: an object of type 'string'
Set this property to the name of the function that performs the client-side validation.
Because the client validation function runs on the target browser, the function must be written using a scripting language supported by the browser, such as JScript or VBScript.
This property cannot be set by themes or style sheet themes. For more information, see and ASP.NET Themes Overview.
Gets or sets the name of the custom client-side script function used for validation.
1.0.5000.0
2.0.0.0
System.Web.UI.Themeable(false)
System.ComponentModel.DefaultValue("")
Method
System.Boolean
To be added
Checks the properties of the control for valid values.
true if the control properties are valid; otherwise, false.
1.0.5000.0
2.0.0.0
Method
System.Boolean
To be added
Overrides the method.
true if the value in the input control is valid; otherwise, false.
1.0.5000.0
2.0.0.0
Method
System.Boolean
The event is raised when validation is performed on the server.
Raising an event invokes the event handler through a delegate. For more information, see Events and Delegates.
The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
Raises the event for the control.
true if the value specified by the parameter passes validation; otherwise, false.
The value to validate.
1.0.5000.0
2.0.0.0
Event
System.Web.UI.WebControls.ServerValidateEventHandler
The event is raised when validation is performed on the server. This event is used to provide a custom validation routine for an input control, such as a control.
For more information about handling events, see Events and Delegates.
Occurs when validation is performed on the server.
1.0.5000.0
2.0.0.0
Property
2.0.0.0
System.ComponentModel.DefaultValue(false)
System.Web.UI.Themeable(false)
System.Boolean
To be added.
Each validator can be associated with a targeted control. In previous versions of the .NET Framework, if the targeted control had an empty string value, such as a property having a value of , the validator (except for the validator) would not evaluate the targeted control and would simply return that the validation passed.
The property is new for the .NET Framework version 2.0. If is set to true, the validator evaluates the control's value (using the criteria specified to the control) and returns the validation results. This property allows developers to evaluate the results of a control regardless of the value of the targeted control.
This property cannot be set by themes or style sheet themes. For more information, see and ASP.NET Themes Overview.
Gets or sets a Boolean value indicating whether empty text should be validated.