Return to Snippet

Revision: 72164
at May 24, 2017 04:28 by MaisieLawson


Initial Code
<asp:Calendar Visible="false" ID="DisabledWeekendsCalendar" runat="server" ondayrender="DisabledWeekendsCalendar_DayRender"></asp:Calendar>

Finally, in your .NET code, create the method which checks to see if a day is a weekend, and if so disables it.

protected void DisabledWeekendsCalendar_DayRender(object sender, DayRenderEventArgs e)
    {
        if (e.Day.Date.DayOfWeek == DayOfWeek.Saturday || e.Day.Date.DayOfWeek == DayOfWeek.Sunday)
        {
            e.Day.IsSelectable = false;
            e.Cell.ForeColor = System.Drawing.Color.Gray;
        }
    }

Initial URL


Initial Description
I wanted to share this information with everyone, especially those who are at the initial level and starting their hands on ASP.NET. Disabling a range of dates on a calendar control is a great way to reduce data-entry error.  For example, imagine a scheduling system for an organization whose doors are open Monday through Friday.  Ideally, any calendar controls should disable Saturday and Sunday to prevent users from accidentally choosing them.  This can be accomplished by taking advantage of the moneylender event of the calendar control.  First, in your asp markup, wire up a method to the event.
If you think that you know some better techniques or you belong to a well reputed <a href="https://www.ingic.ae/dubai/software-development">software development companies in Dubai</a> then please share your thoughts and suggestions.

Initial Title
Disable Days on ASP.NET Calendar Control

Initial Tags


Initial Language
ASP