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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.