Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Calendar.SelectedDate / VisibleDate - ASP.Net 2.0

Posted on 2006-07-04
4
1,993 Views
Last Modified: 2010-08-05
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
Comment
Question by:ttnetworks
4 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 17035843
On Page_Load  do the following:

 calTimesheetDate.SelectedDate = Now.Date

hope it helps u :)
thanx
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 17035847
Try using DateTime.Today; rather than DateTime.Now;
0
 
LVL 5

Expert Comment

by:vinodhsomasekharan
ID: 17036602
0
 

Expert Comment

by:MailCo_Developer
ID: 23412507
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question