• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2065
  • Last Modified:

Calendar.SelectedDate / VisibleDate - ASP.Net 2.0

Hi,

OK, this is probably really simple, but for some reason it just does not want to work. In ASP.Net 1.1 I used to place Calendar controls on a page, then set today's date as the selected date on page load. The calendar control would then display today as the selected date.

In ASP.Net 2.0 this does not seem to work. I have the following control declared:

                <asp:Calendar ID="calTimesheetDate" runat="server" SelectionMode="Day" ShowGridLines="true">
                    <SelectedDayStyle BackColor="Yellow" ForeColor="Red" />
                </asp:Calendar>

On Page_Load I do the following:

                calTimesheetDate.SelectedDate = DateTime.Now;
                calTimesheetDate.VisibleDate = DateTime.Now;

However even though this does actually select the date of the control in memory, i.e. if I get the date from the control somewhere else on the page, it works. BUT the calendar control does not show that the date is selected.

It only displays the selected date when it is clicked on.

Why is this ???
0
ttnetworks
Asked:
ttnetworks
1 Solution
 
Pratima PharandeCommented:
On Page_Load  do the following:

 calTimesheetDate.SelectedDate = Now.Date

hope it helps u :)
thanx
0
 
Carl TawnSystems and Integration DeveloperCommented:
Try using DateTime.Today; rather than DateTime.Now;
0
 
vinodhsomasekharanCommented:
0
 
MailCo_DeveloperCommented:
The key is that the selected date needs to be in date format not date time.  So for example if you wanted to set the selected date in code behind you could do this:


Calendar.SelectedDate = CType(dtLocation.Rows(0)("Next_Due_Date"), Date).Date

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now