Site Search:
Sign in | Join | Help
4Penny.net

ASP.NET

Notes, Tricks and Tips on ASP.NET Coding

ASP.NET Validation Contols

This is not a primer on ASP.NET Validation controls, there are plenty of those out there. This is just my handy little piece of cheat code - it's easier to copy it out of here when I need it...

First, place the ValidationSummary control on the page. We'll have the individual controls display an '*' for error, and the Summary control will show the error text

<asp:ValidationSummary id="valSummary" runat="server"
    HeaderText="Errors:"
    ShowSummary="true" DisplayMode="List" />


 

This RegularExpressionValidator will make sure that the validate field has one to three numeric characters:

<asp:RegularExpressionValidator runat="server" ID="regexpAge" 
    ControlToValidate="txtReqShipDays"
    ValidationExpression="^\d{1,3}$" 
    ErrorMessage="Req Ship Days must be one to three digits."
    Display="Dynamic" Text="*" />

Other regex expressions to use:

"^\d" - numeric only

This RequiredFieldValidator will be sure that a field is not left empty:

<asp:RequiredFieldValidator runat="server" ID="reqAge" ControlToValidate="txtReqShipDays"
ErrorMessage="Missing Req Ship Days" Text="*" Display="Dynamic" />

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add

About Steve Gray

Steve is a seasoned (translate: old) developer in VB and ASP.NET. He spends most of his time in Dynamics GP, writing custom mods for consulting firms. Crystal reports, eConnect, VS Tools for Dynamics... anything that comes along.