Skip to Main Content
ASP.NET 4 24-Hour Trainer
book

ASP.NET 4 24-Hour Trainer

by Toi B. Wright
July 2010
Beginner content levelBeginner
552 pages
10h 14m
English
Wrox
Content preview from ASP.NET 4 24-Hour Trainer

Chapter 17A. Custom Validators in Web Forms

In Lesson 16A I showed you how to use all of the standard validation controls. Sometimes, you will find that none of the standard validation controls perform the exact type of validation that you need. In this lesson I show you how to create and use a CustomValidator control.

The CustomValidator control uses all of the same properties as the standard validation controls, plus two very unique properties. These are the unique properties of the CustomValidator:

  • ClientValidationFunction — This is the name of the client-side script used to perform validation on the client. This property is not required.

  • ValidateEmptyText — This Boolean property is used to trigger validation when the value of input field specified by the ControlToValidate property is empty. The default value is false.

Another unique feature of the CustomValidator is that the ControlToValidate property is not required. If the ControlToValidate property is left blank, the CustomValidator is always triggered on postback, unless it belongs to a different ValidationGroup from the control that triggered the postback.

The CustomValidator has one unique event:

  • ServerValidate — This event is raised when the custom validation is performed on the server. This is required.

This is the markup for a CustomValidator:

<asp:CustomValidator ID="CustomValidator1" runat="server"
    ErrorMessage="CustomValidator"
    OnServerValidate="CustomValidator1_ServerValidate" />

Notice that the OnServerValidate method points ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 4 24-Hour Trainer

ASP.NET 4 24-Hour Trainer

Toi B. Wright
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9780470596913Purchase bookExamplesErrata