Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi All,

How can I disable dates in datepicker that are less than a particular date and handled in App.xaml for all datepickers. I used DisplayDateStart property. But, if user entered the date less than a particular date, I want to clear it. Please, let me know if it is possible.
Posted
Updated 10-Dec-12 18:38pm
v3
Comments
Sergey Alexandrovich Kryukov 2-Jan-13 23:40pm    
A warning for you: you post some comment as a "solution". You should not do it. But by some weird reason, you even accepted this "answer" formally. This is already outrageous. And such things cannot help you; all you can get is some down-votes and abuse reports; those unpleasant things you don't want.
—SA

try this it is confirm code:
1. First add java script to head section
XML
<script type="text/javascript">
     function checkDate(sender, args) {
         if (sender._selectedDate < new Date()) {
             alert("You cannot select a day earlier than today!");
             sender._selectedDate = new Date();
             // set the date back to the current date
             sender._textbox.set_Value(sender._selectedDate.format(sender._format))
         }
     }
    </script>


2.then call it into date picker like this:
XML
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
   <asp:CalendarExtender ID="TextBox1_CalendarExtender"  OnClientDateSelectionChanged="checkDate" runat="server"
       TargetControlID="TextBox1">
   </asp:CalendarExtender>
   </form>



Its End:

I Also put all page code for better understating for you:

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

<%@ 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">
 <script type="text/javascript">
     function checkDate(sender, args) {
         if (sender._selectedDate < new Date()) {
             alert("You cannot select a day earlier than today!");
             sender._selectedDate = new Date();
             // 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">
 <%-- <iframe src="http://www.cricinfo.com" height="700px" width="700px"></iframe>--%>



    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:CalendarExtender ID="TextBox1_CalendarExtender"  OnClientDateSelectionChanged="checkDate" runat="server"
        TargetControlID="TextBox1">
    </asp:CalendarExtender>
    </form>


</body>
</html>
 
Share this answer
 
Comments
Arun kumar Gauttam 11-Dec-12 2:10am    
i compare date to today date
josh-jw 11-Dec-12 2:28am    
thanks for reply.i think this should be work in asp page.but i am working in wpf application.if you have any idea please suggest me.
Arun kumar Gauttam 11-Dec-12 3:32am    
i am use that code in just simple asp.net page, i not have any idea about wpf application
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900