Saturday, April 19, 2014

Date Range Validation in AJAX CalendarExtender Control using ASP.Net Range Validator

In this article I will explain how to implement Range Validation in ASP.Net AJAX Control Toolkit CalendarExtender Control.

 

<form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
   
    <asp:TextBox ID="txtDate" runat="server" ReadOnly = "true"></asp:TextBox>
    <br />
    <asp:RangeValidator runat="server" ID="RangeValidator1" Type="Date" ControlToValidate="txtDate" MaximumValue='09/20/2011' MinimumValue="09/01/2011"
    ErrorMessage="Date should be between 09/01/2011 and 09/20/2011" Display="Dynamic" />
   
    <cc1:CalendarExtender ID = "Calender1" runat = "server" TargetControlID = "txtDate"></cc1:CalendarExtender>
    <br />
    <asp:Button ID="Button1" runat="server" Text="Submit" />
</form>


Above you will notice that I have an ASP.Net TextBox Control txtDate for which I have specified AJAX Control Toolkit CalendarExtender Control Calender1.



Also I have specified ASP.Net RangeValidator Control RangeValidator1 for the TextBox txtDate. This range validator will throw error when the selected date does not fit in the specified range.



In order to make the Range Validator work for the Dates. You need to specify the following paramaters



Type – Specifies that the range validations are for Dates.



MinimumValue – Specifies the minimum value of the range.



MaximumValue - Specifies the minimum value of the range.



 



Screenshot



Implement Range Validation in AJAX Control Toolkit CalendarExtender Control.

0 comments:

Post a Comment