locked
How to disable past dates in calender extender RRS feed

  • Question

  • hii there

    Can  anybody help me  to  disable past dates from calender extender by comparing with current date?

    • Moved by Lie You Monday, April 2, 2012 3:02 AM ASP.Net related. (From:.NET Base Class Library)
    Tuesday, March 27, 2012 12:46 PM

Answers

  • Hi biscos,

    please check this:

    <script language=”javascript” type=”text/javascript”>
    
    function CheckForPastDate(sender, args) {
    
    var selectedDate = new Date();
    
    selectedDate = sender._selectedDate;
    
    var todayDate = new Date();
    
    if (selectedDate.getDateOnly() < todayDate.getDateOnly()) {
    
    sender._selectedDate = todayDate;                  sender._textbox.set_Value(sender._selectedDate.format(sender._format));
    
    alert(“Date Cannot be in the past”);
    
    }
    
    }
    
    </script>
    
    <asp:TextBox ID=”txtDate” contentEditable=”false” runat=”server” CssClass=”txtcss”></asp:TextBox>&nbsp;
    
    
    <asp:Image ID=”imgCal” runat=”server” ImageUrl=”~/img/calendar.gif” />
    
    
    <cc1:CalendarExtender ID=”CalExtDate” runat=”server” FirstDayOfWeek=”Sunday” PopupButtonID=”imgCal”PopupPosition=”BottomLeft” Format=”dd/MM/yyyy” OnClientDateSelectionChanged=”CheckForPastDate” TargetControlID=”txtDate”>
    
    </cc1:CalendarExtender>


    Regards, http://shwetamannjain.blogspot.com

    • Proposed as answer by Shweta Jain (Lodha) Sunday, April 1, 2012 4:06 PM
    • Marked as answer by biscos Tuesday, April 24, 2012 3:58 PM
    Sunday, April 1, 2012 4:06 PM

All replies

  • If you are talking about ASP.Net then this code can work...

    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e){
            if (e.Day.Date < DateTime.Now.Date){
                e.Day.IsSelectable = false;
                e.Cell.ForeColor = System.Drawing.Color.Gray;
            }
      }

    Regards


    Anirban Bhattacharya (Lead Consultant - ESSPL)

    • Proposed as answer by Lie You Thursday, March 29, 2012 3:24 AM
    Tuesday, March 27, 2012 1:14 PM
  • but i want to validate datetime on client side...the above code take a trip of server to validate...simply it is a server side validation

    any other possible way to do this

    Wednesday, March 28, 2012 10:37 AM
  • Never mind, no where you wrote, you need client side validation or even you are asking about ASP.Net. For any ASP.Net question we need to go to http://forums.asp.net/ which is the forum request.

    Regards,


    Anirban Bhattacharya (Lead Consultant - ESSPL)

    Wednesday, March 28, 2012 10:43 AM
  • Hi biscos,

    please check this:

    <script language=”javascript” type=”text/javascript”>
    
    function CheckForPastDate(sender, args) {
    
    var selectedDate = new Date();
    
    selectedDate = sender._selectedDate;
    
    var todayDate = new Date();
    
    if (selectedDate.getDateOnly() < todayDate.getDateOnly()) {
    
    sender._selectedDate = todayDate;                  sender._textbox.set_Value(sender._selectedDate.format(sender._format));
    
    alert(“Date Cannot be in the past”);
    
    }
    
    }
    
    </script>
    
    <asp:TextBox ID=”txtDate” contentEditable=”false” runat=”server” CssClass=”txtcss”></asp:TextBox>&nbsp;
    
    
    <asp:Image ID=”imgCal” runat=”server” ImageUrl=”~/img/calendar.gif” />
    
    
    <cc1:CalendarExtender ID=”CalExtDate” runat=”server” FirstDayOfWeek=”Sunday” PopupButtonID=”imgCal”PopupPosition=”BottomLeft” Format=”dd/MM/yyyy” OnClientDateSelectionChanged=”CheckForPastDate” TargetControlID=”txtDate”>
    
    </cc1:CalendarExtender>


    Regards, http://shwetamannjain.blogspot.com

    • Proposed as answer by Shweta Jain (Lodha) Sunday, April 1, 2012 4:06 PM
    • Marked as answer by biscos Tuesday, April 24, 2012 3:58 PM
    Sunday, April 1, 2012 4:06 PM
  • thnx Shweta mame ur code really works for me.....

    thnx once again....

    Tuesday, April 24, 2012 4:02 PM