Asked by:
How to disable Date's in Calendar Control

Question
-
User1046245955 posted
How to disable Date's in Calendar Control?
for example: disable the date from May 1-10, 2018
<asp:TextBox ID="date" runat="server" AutoPostBack="true" CssClass="form-control" placeholder="Date" Width="20%" OnTextChanged="date_TextChanged"></asp:TextBox>
<asp:CalendarExtender ID="c_date" runat="server" Format="dd-MMM-yyyy" TargetControlID="date">
</asp:CalendarExtender>Tuesday, April 24, 2018 10:53 AM
All replies
-
User1623409651 posted
Hi,
<asp:CalendarExtenderID="Calendar1"runat="server" Enabled="True" TargetControlID="TextBox1"Format="dd/MM/yyyy" ></asp:CalendarExtender> protected void Page_Load(object sender, EventArgs e) { Calendar1.StartDate = DateTime.Now; //to dissable past Date }
Calendar1.EndDate = DateTime.Now; //to dissable future Date
OR
Refer the below link
Thanks
Tuesday, April 24, 2018 11:03 AM -
User1046245955 posted
not this one. i need to disabled a date period...
for example:
May 1 - 10, 2018 Disabled in calendar and May 11 up to up is enabled
Tuesday, April 24, 2018 12:18 PM -
User-492460945 posted
Hi paminchever,
Simply assign start date to c_date as follows,
c_date.StartDate = DateTime.Now;
Thanks,
RajeshV.
Tuesday, April 24, 2018 1:18 PM -
User409696431 posted
The second link in paminchever's post contains examples of validating dates for whatever conditions you want to test for. Scroll down to the bottom.
Tuesday, April 24, 2018 3:00 PM -
User1623409651 posted
Hi
Please refer to the subject that disable Weekends & Specific Dates on the Ajax Calendar Extender, here is the link below:
http://forums.asp.net/t/1689931.aspx/1
Hope it helpful to u.
Thanks
Wednesday, April 25, 2018 4:57 AM -
User-1780421697 posted
using System.Drawing; public partial class DefaultCS : System.Web.UI.Page { protected void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e) { // Select all dates in the past just a condition, you can check dates as per your business logic if (e.Day.Date < System.DateTime.Today) { // Disable date e.Day.IsSelectable = false; // Change color of disabled date e.Cell.ForeColor = Color.Gray; } } }
Wednesday, April 25, 2018 5:33 AM -
User-1780421697 posted
Check this article
https://asp-net-example.blogspot.com/2011/09/how-to-disable-calendar-dates-in-aspnet.html
Wednesday, April 25, 2018 5:33 AM -
User-1838255255 posted
Hi paminchever.
After reading your description, as far as I know, there is no direct function or method could achieve your needs. You could do is disable date by startDate, endDate attribution. I think you could use JQuery UI plugin such as datepicker which could disable some specific date via BeforeShowDay(). For more details, please check the following tutorials:
Jquery UI datepicker. Disable array of Dates:
https://stackoverflow.com/questions/15400775/jquery-ui-datepicker-disable-array-of-dates
How to Disable Dates in Jquery DatePicker – A Short Guide:
http://www.spiceforms.com/blog/how-to-disable-dates-in-jquery-datepicker-a-short-guide/
If you could use MS Calendar Control, you can override the calendar_dayRender() to get your needs:
if (e.Day.Date>=new DateTime(2018,5,1)&&e.Day.Date<new DateTime(2018,5,11)) { e.Cell.BackColor = System.Drawing.Color.LightGray; e.Day.IsSelectable = false; }
Best Regards,
Eric Du
Wednesday, April 25, 2018 8:06 AM