| DateTime Selector 2.0 | VB.Net Examples | |
|
|
|
|
Setting the Default Date |
|
|
Drag a DateTimeSelector WebControl from your toolbox onto a aspx page (WebForm). If you do not have a DateTimeSelector WebControl in your toolbox please read VS.Net Setup for full instructions. Copy and paste
the following code into the page_load method of your WebForm. In this example we will set the default
Selected date to exactly three months from today. Do this when the page first loads so any changes a user makes will be reflected in the SelectedDate property during subsequent postbacks.
There are a number of Style options available including BackColor,
CssClass and ForeColor. These are also separately available for the Time portion of the display (Time Display).
If you wish to change the font within the DateTime selector use a CssClass. To view all style options right
click the webcontrol (In design view) and select properties. |
|
' setting the default date ..
during first page load
If Not Me.IsPostBack
Then
Dim myDate As
DateTime
myDate = DateTime.Now.AddMonths(3) ' 3 months from
today
DateTimeSelector1.SelectedDate = myDate
End If
|
|
|
|
|
|
Setting The Year Range |
|
|
The number of years displayed depends on the PreYearOffSet and PostYearOffSet properties. The PreYearOffSet property determines the number of years that will be displayed before the SelectedDate. The PostYearOffSet determines the number of years that will be displayed after the SelectedDate . If you only wish to display the currently selected date year use the following example. By default the year range is set at 2 years before and 7 years after the SelectedDate. |
|
' setting the default date ..
during first page load
If Not Me.IsPostBack
Then
Dim myDate As
DateTime
myDate = DateTime.Now.AddMonths(3) ' 3 months from
today
DateTimeSelector1.SelectedDate = myDate
End If
' To display
only the selected year
DateTimeSelector1.PreYearOffSet = 0;
'don't display preceeding years
DateTimeSelector1.PostYearOffSet = 1; 'display current year
|
|
|
|
|
|
Getting the Selected Date |
|
|
For this example Use the same WebForm you created in the previous example. Drag and Drop a Button
onto the WebForm and click it to reveal the Button Clicked event. Copy and paste the following code.
When the page is running clicking the button will write the selected date to the page. |
|
Dim selectedDate
As DateTime
selectedDate = DateTimeSelector1.SelectedDate ' get selected
date
Response.Write(selectedDate.ToString()) ' display
using response write
|
|
|
|
|
|
Client Validation |
|
|
Client Validation causes an alert box to popup when a invalid date has been selected. For example, selecting
31 Feb 2003 will cause a client validation because there are only 28 days in Feb 2003.
By Default Client Validation is used. You have the option of turning this off by setting ClientDateValidation to false. If Client Validation is not used any date that has a selected day over the limit for the selected month
will default to the highest number of days allowed for that month.
You also have the option of changing the message that is displayed to the user when the validation alert
is raised. By default the ValidateMessage property reads 'The selected month does not have this many days!' |
|
|
|
|
|
|
|
Display Format |
|
|
There are 8 display formats available.
1. YYMMDD Year, Month and Day
2. YYMMDDHH Year, Month, Day and (24) Hour
3. YYMMDDHHMM Year, Month, Day, (24) Hour and Minute
4. YYMMDDHHMMSS Year, Month, Day, (24) Hour, Minute and Second
5. MMYYDD Month, Year and Day
6. MMYYDDHH Month, Year and Day and (24) Hour
7. MMYYDDHHMM Month, Year and Day, (24) Hour and Minute
8. MMYYDDHHMMSS Month, Year and Day, (24) Hour, Minute and Second
All month names are based on the culture settings at the server.
|
|
|
|
|
|
|