Introduction
In my previous articles I told you about:
- How to Determine Age Using Ajax Calendar in ASP.NET Application
- How to Calculate Age by Inserting DOB Manually.
- How to Apply Client-side Validation on DOB Selected by User.
This article will explain how to apply server-side validation on a DOB selected by the user. Earlier articles clearly described how to calculate the age of the user but what if the user selects a date from the future! Or selects a date from 1800 or even earlier than that! We should create an application that should stop the user from selecting invalid dates. This can be done both by client-side validations or through server-side validations. This article will cover only server-side validation, if you want to have client-side validation then you should follow my previous article.
Step 1
I am working on my previous application so most of the code is the same. If you are a new viewer then you must add two Textboxes and a Button to your application. First the TextBox for getting the DOB from the user and the other for showing the age.
- <asp:TextBox ID="txtDATE_OF_BIRTH" runat="server" Font-Size="12px" ></asp:TextBox>
- <label id="Label34" runat="server" style="color:Gray; font-size:9px">Focus on Textbox to see Calender</label>
- </td>
- </tr>
- <tr>
- <td >
- <asp:Label ID="Label35" runat="server" CssClass="lbl1" Text="Age"></asp:Label>
- </td>
- <td >
- <asp:TextBox ID="txtCONSULTANT_AGE" runat="server" Font-Size="12px" ></asp:TextBox>
- </td>
- ;/tr>
- <tr>
- <td>
- <asp:Button runat="server" Text="Submit"></asp:Button>
- </td>
- </tr>
Here txtDATE_OF_BIRTH will be used to show the calendar and txtCONSULTANT_AGE will be used for showing the age of the user.
Step 2
Now you should call an Ajax Calendar Extender.
- <cc1:CalendarExtender runat="server" TargetControlID="txtDATE_OF_BIRTH" Format="yyyy-MM-dd" OnClientDateSelectionChanged="SelectDate" ID="CalendarExtender1"></cc1:CalendarExtender>





Join the conversation! Your thoughts help the community grow.