Posted By

MaisieLawson on 05/24/17


Tagged


Versions (?)

Disable Days on ASP.NET Calendar Control


 / Published in: ASP
 

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 software development companies in Dubai then please share your thoughts and suggestions.

  1. <asp:Calendar Visible="false" ID="DisabledWeekendsCalendar" runat="server" ondayrender="DisabledWeekendsCalendar_DayRender"></asp:Calendar>
  2.  
  3. Finally, in your .NET code, create the method which checks to see if a day is a weekend, and if so disables it.
  4.  
  5. protected void DisabledWeekendsCalendar_DayRender(object sender, DayRenderEventArgs e)
  6. {
  7. if (e.Day.Date.DayOfWeek == DayOfWeek.Saturday || e.Day.Date.DayOfWeek == DayOfWeek.Sunday)
  8. {
  9. e.Day.IsSelectable = false;
  10. e.Cell.ForeColor = System.Drawing.Color.Gray;
  11. }
  12. }

Report this snippet  

You need to login to post a comment.