Creating a Custom Validation Function

If the built-in validation controls (shown earlier in Table 17-1) don't match your validation needs, you can create custom validation functions using the CustomValidator control. Listing 17-14 shows the CustomValidator control applied to the TextBox control that collects the number of minutes from the user.

Listing 17-14. Using the CustomValidator control

... <div> <asp:Label ID="Label3" runat="server" Text="Minutes:" CssClass="label"/> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <asp:CustomValidator ID="CustomValidator1" runat="server"         ControlToValidate="TextBox3"         ErrorMessage="Enter a whole number of minutes that is less than 50"         Text="*"         onservervalidate="CustomValidator1_ServerValidate" ...

Get Applied ASP.NET 4 in Context now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.