473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Asp.Net Calendar: get date on page load

How do you get the Calendar date when the page first loads?

I have this code (which works once the user selects a date) - I get
"12:00:00 AM" for the label.text when the page first loads:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Label1.Text = Calendar1.SelectedDate
End Sub

Protected Sub Calendar1_SelectionChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Calendar1.SelectionChanged
Label1.Text = Calendar1.SelectedDate
End Sub

I actually have a ton of code that runs when the user changes the date
(pulling info from a database), but I'd like this code to run on the
first time the page loads.

I'd like to call the Calendar1_SelectionChanged sub in the page load
sub using:
"Call Calendar1_SelectionChanged(Calendar1,e)"
but I don't know how to pass the current date (unless I'm doing it
wrong!)

Thanks

Mar 14 '07 #1
6 4519
<de**********@gmail.comwrote in message
news:11*********************@n59g2000hsh.googlegro ups.com...
How do you get the Calendar date when the page first loads?
I have this code (which works once the user selects a date) - I get
"12:00:00 AM" for the label.text when the page first loads:
Yes, well you will because no date has been selected yet...

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Calendar1.SelectedDate = DateTime.Now
Label1.Text = Calendar1.SelectedDate
End Sub
Mar 14 '07 #2
A calendar doesn't have a "current" date, as you put it. It has (possibly)
a selected date, and it has a month and year property. If you want the
current date the first time the page loads, just use the Date object.
<de**********@gmail.comwrote in message
news:11*********************@n59g2000hsh.googlegro ups.com...
How do you get the Calendar date when the page first loads?

I have this code (which works once the user selects a date) - I get
"12:00:00 AM" for the label.text when the page first loads:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Label1.Text = Calendar1.SelectedDate
End Sub

Protected Sub Calendar1_SelectionChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Calendar1.SelectionChanged
Label1.Text = Calendar1.SelectedDate
End Sub

I actually have a ton of code that runs when the user changes the date
(pulling info from a database), but I'd like this code to run on the
first time the page loads.

I'd like to call the Calendar1_SelectionChanged sub in the page load
sub using:
"Call Calendar1_SelectionChanged(Calendar1,e)"
but I don't know how to pass the current date (unless I'm doing it
wrong!)

Thanks

Mar 14 '07 #3
Thanks to you both - I guess what I really want is for my code to run
when the page first loads.

Right now, the code doesn't run until the user picks the day (which
would usually be the current date, which is highlighted when the page
first loads)

I used the label.text as just an example - the real code grabs a bunch
of info from a database and displays it when ever the user changes the
day.

I could just copy it all from Calendar1_SelectionChanged to Page_Load,
but that seems inefficient (having it twice).

Mar 14 '07 #4
<de**********@gmail.comwrote in message
news:11**********************@e1g2000hsg.googlegro ups.com...
I could just copy it all from Calendar1_SelectionChanged to Page_Load,
but that seems inefficient (having it twice).
So create a private function for it, and call it whenever you need to...
Mar 14 '07 #5
On Mar 14, 4:38 am, "Mark Rae" <m...@markNOSPAMrae.comwrote:
<dean.h.br...@gmail.comwrote in message

news:11**********************@e1g2000hsg.googlegro ups.com...
I could just copy it all from Calendar1_SelectionChanged to Page_Load,
but that seems inefficient (having it twice).

So create a private function for it, and call it whenever you need to...
Thanks - sometime the obvious, easy choice gets overlooked on those
late nights!

Mar 15 '07 #6
<de**********@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
>So create a private function for it, and call it whenever you need to...

Thanks - sometime the obvious, easy choice gets overlooked on those
late nights!
We've all been there... :-)
Mar 15 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: goochey | last post by:
I'm trying to convert a Julian Date (Format "4365") into an actual calendar date in Visual Basic, can anyone help me out with this.
1
by: WFB | last post by:
Hi, I have a base class from which all of my pages derive (ABCBasePage). For example, ABCCustomerSelect Inherits ABCPasePage. I would now like to have ABCPocketSelect which should inherit from...
7
by: Goober | last post by:
I have a page that receives a session variable from the default.aspx. On Page load, the code in Page load gets executed twice. So far, no problem. It sets the session variable each time,...
3
by: Jason | last post by:
I have an ASP.NET application in which I would like to call my button click event (imgSubmitSearch_Click) on the page load if certain criteria are met. Is this possible? What is the correct...
4
by: Marcus | last post by:
Hi, I'm looking for useful starting points, suggestions, and sample code, to implement a calendar iterator. Simply, the iterator is seeded with an initial calendar date, e.g., "03-12-2006", and...
7
by: mesubham | last post by:
In VB toolbox, I put a window calendar, I have also put a textbox beside calendar. What is the code of VB6, when I click on calendar date, it will transfer to the textbox in dd/mm/yyyy format?
10
by: sweatha | last post by:
Hi Can anybody help me how to block all dates in calendar control till the current date.
1
by: newphpcoder | last post by:
I changed my database from mysql 4.1.10 to mysql 5.0 and I encountered error in my calendar event page. The output of my calendar date was change instead of date it becomes “>” and also when I press...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.