Click here to Skip to main content
15,032,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I do have a requirement that to disable previous and coming week end dates[saturday and sunday] with in ajax calendar extender control of asp.net. i've tried with many web links answers through net, but unable to get the exact output. if anyone knows any information regarding my requirement please share your views or corresponding code.

Note:- i want this functionality only with ajax calendar extender control not with asp calendar control.




but didn't able to get the output, and it shows an error like "length of undefined.."
and i also want to disable previous dates..please help me to solve this.
Thanks in advance.

What I have tried:

i've tried using following code to disable week ends.
=======================================================
C#
<asp:Textbox id="txtDate" runat="server"/>
<asp:ImageButton id="Imgbtn" runat="server" imageurl="images/calendar.jpg"/>
<ajax:calendarExtender id="DisabledWeekendsCalendar"  runat="server" popupbuttonid="Imgbtn" TargetControlId="txtDate" />


My Javascript function:-
=========================

JavaScript
function DisableWeekends(sender, args) {
  for (var i = 0; i < sender._days.all.length; i++) {
    for (var j = 0; j < 6; j++) {
      if (sender._days.all[i].id == "DisabledWeekendsCalendar" + j + "_0") {
        sender._days.all[i].disabled = true;
      }

      if (sender._days.all[i].id == "DisabledWeekendsCalendar" + j + "_6") {
        sender._days.all[i].disabled = true;
      }
    }
  }
}
Posted
Updated 3-May-16 0:57am
Comments
   
So what exactly you need? Only weekends should be disabled?
pavan_ kumar 3-May-16 6:03am
   
i need both i.e past dates disabling and coming week ends disabling. but i've tried initially to disable the weekends, that's why above code is like that.and that is also not working properly. i'm unable to get where i've written the code wrongly.

1 solution

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


Markup:
<asp:CalendarExtenderID="Calendar1"runat="server" 
    Enabled="True" TargetControlID="TextBox1"Format="dd/MM/yyyy" ></asp:CalendarExtender>


To disable a past date use the following code in the "Page load":
protected void Page_Load(object sender, EventArgs e)
{
   Calendar1.StartDate = DateTime.Now;   //to dissable past Date
}


To disable a future date use the following code in the "Page load":
protected void Page_Load(object sender, EventArgs e)
{
   Calendar1.EndDate = DateTime.Now;   //to dissable future  Date
}
   

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