Calendar webcontrol and hiding weekend days

N

Namespace

Hi

Simple question - I want to hide or disable the possibility to select
weekend days in the calendar control in asp.net!

How do I do that?

Thanks
"Namespace"
 
N

Nathan Sokalski

I don't know of any built-in methods to disable the selecting of weekend
dates, but here is a simple idea that might accomplish the same thing:

1. Set the properties of the WeekendDayStyle so that the weekends appear
invisible by making the BackColor and ForeColor the same, as follows:
<asp:Calendar id="Calendar1" runat="server">
<WeekendDayStyle ForeColor="White" BackColor="White"></WeekendDayStyle>
</asp:Calendar>

2. Write an event handler for the SelectionChanged event that will display
an error or message letting the user know they have chosen an invalid date
when they choose a weekend. Here is some simple code of mine (my code simply
displays whether it is a weekend or weekday, you will want to custumize the
code for your purposes):
Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Calendar1.SelectionChanged
If Calendar1.SelectedDate.DayOfWeek = DayOfWeek.Saturday OrElse
Calendar1.SelectedDate.DayOfWeek = DayOfWeek.Sunday Then
lblDayType.Text = "Weekend"
Else
lblDayType.Text = "Weekday"
End If
End Sub

If you plan on using validation on your page, you may want to use a
CustomValidator to do this instead (the If condition would still be the
same, you would simply be setting the args.IsValid property instead of
displaying a message).

Good Luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,365
Latest member
BurtonMeec

Latest Threads

Top