Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select current date by default in ASP.Net Calendar control

Let's say I have an aspx page with this calendar control:

<asp:Calendar ID="Calendar1" runat="server"  SelectedDate="" ></asp:Calendar>

Is there anything I can put in for SelectedDate to make it use the current date by default, without having to use the code-behind?

like image 499
Joel Coehoorn Avatar asked Sep 17 '08 18:09

Joel Coehoorn


People also ask

How can set date in calendar control in asp net?

TodaysDate = tomorrow; Calendar1. SelectedDate = Calendar1. TodaysDate; The following example shows how you can fill a DropDownList control with a selection of dates and then set the value of today's date in the Calendar control according to the user's selection from the list.

Which is the default event of calendar control?

By default, the control displays the days of the month, day headings for the days of the week, a title with the month name and year, links for selecting individual days of the month, and links for moving to the next and previous month.

What is the use of calendar control in asp net?

The calendar control is a functionally rich web control, which provides the following capabilities: Displaying one month at a time. Selecting a day, a week or a month. Selecting a range of days.


2 Answers

If you are already doing databinding:

<asp:Calendar ID="Calendar1" runat="server"  SelectedDate="<%# DateTime.Today %>" />

Will do it. This does require that somewhere you are doing a Page.DataBind() call (or a databind call on a parent control). If you are not doing that and you absolutely do not want any codebehind on the page, then you'll have to create a usercontrol that contains a calendar control and sets its selecteddate.

like image 83
Philip Rieck Avatar answered Sep 17 '22 17:09

Philip Rieck


DateTime.Now will not work, use DateTime.Today instead.

like image 29
Kevin Avatar answered Sep 18 '22 17:09

Kevin