473,796 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EventArg s) Handles Me.Load
Label1.Text = Calendar1.Selec tedDate
End Sub

Protected Sub Calendar1_Selec tionChanged(ByV al sender As
System.Object, ByVal e As System.EventArg s) Handles
Calendar1.Selec tionChanged
Label1.Text = Calendar1.Selec tedDate
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_Selec tionChanged sub in the page load
sub using:
"Call Calendar1_Selec tionChanged(Cal endar1,e)"
but I don't know how to pass the current date (unless I'm doing it
wrong!)

Thanks

Mar 14 '07 #1
6 4534
<de**********@g mail.comwrote in message
news:11******** *************@n 59g2000hsh.goog legroups.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.EventArg s) Handles Me.Load
Calendar1.Selec tedDate = DateTime.Now
Label1.Text = Calendar1.Selec tedDate
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**********@g mail.comwrote in message
news:11******** *************@n 59g2000hsh.goog legroups.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.EventArg s) Handles Me.Load
Label1.Text = Calendar1.Selec tedDate
End Sub

Protected Sub Calendar1_Selec tionChanged(ByV al sender As
System.Object, ByVal e As System.EventArg s) Handles
Calendar1.Selec tionChanged
Label1.Text = Calendar1.Selec tedDate
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_Selec tionChanged sub in the page load
sub using:
"Call Calendar1_Selec tionChanged(Cal endar1,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_Selec tionChanged to Page_Load,
but that seems inefficient (having it twice).

Mar 14 '07 #4
<de**********@g mail.comwrote in message
news:11******** **************@ e1g2000hsg.goog legroups.com...
I could just copy it all from Calendar1_Selec tionChanged 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...@markNOSPA Mrae.comwrote:
<dean.h.br...@g mail.comwrote in message

news:11******** **************@ e1g2000hsg.goog legroups.com...
I could just copy it all from Calendar1_Selec tionChanged 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**********@g mail.comwrote in message
news:11******** **************@ l77g2000hsb.goo glegroups.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
16337
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
6960
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 ABCCustomerSelect. My problem is that when ABCPocketSelect is loaded the Page_Load event in ABCBasePage is called, followed by the load event for ABCCustomerSelect - and I would like to skip the ABCCustomerSelect load event.. My basic code is...
7
3948
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, correctly. However, when I click on a menu item in that page, it then executes the same page load twice, before transferring control (via a response.redirect) to the new page. On the first pass through the page load of the menu page, the session...
3
4254
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 syntax to be able to programmatically have my imgSubmitSearch button clicked? I tried the obvious, Call imgSubmitSearch, but intellisense doesn't like that due to the sender / e arguments. Private Sub imgSubmitSearch_Click(ByVal sender As...
4
2207
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 then subsequent calls to next return subsequent dates. The seed could be a standard calendar/datetime object. 03-12-2006
7
14862
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
1907
by: sweatha | last post by:
Hi Can anybody help me how to block all dates in calendar control till the current date.
1
1377
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 the button to move to another month I can’t move to another month. I have no idea why it happened. Here is the old calendar code: <?php $dbCnx = @mysql_connect("localhost","", "") or die('Could not Connect to the database')...
0
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10239
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10190
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10019
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9057
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.