Friday, 2 August 2013

date validation in ajax calender extender

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
        function checkDate(sender, args) {
        
          var toDate= new Date();

            toDate.setMinutes(0);

            toDate.setSeconds(0);

            toDate.setHours(0);

            toDate.setMilliseconds(0);

            if (sender._selectedDate > toDate) {

                alert("You can't select day greater than today!");

                sender._selectedDate = toDate;

                //set the date back to the current date

                sender._textbox.set_Value(sender._selectedDate.format(sender._format))
            }

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
    <div>
    <asp:TextBox ID="tb" runat="server"></asp:TextBox>
        <asp:CalendarExtender ID="CalendarExtender1" runat="server"
            TargetControlID="tb" OnClientDateSelectionChanged="checkDate"
            DaysModeTitleFormat="dd-mmm-yyyy" Format="dd-MMM-yyyy">
        </asp:CalendarExtender>
    </div>
    </form>
</body>
</html>

No comments:

Post a Comment