Solved

How do I Auto update a label with the current date when a page loads (ASP.Net VB)?

Posted on 2009-03-31
6
473 Views
Last Modified: 2013-11-07
I have created a label on an ASP.Net page that I want to show the current date & time every time the page is loaded/refreshed., but Im a little rusty having not programmed for more than four years.  I was trying to use the NOW() function but cant remember the syntax for creating a page load event.
0
Comment
Question by:kieranlarkin
  • 2
  • 2
  • 2
6 Comments
 
LVL 2

Expert Comment

by:Causality
ID: 24027425
put a Label on your Form.
then you can write this code on FormOnLoad event


        private void Form1_Load(object sender, EventArgs e)
        {
             label1.Text=DateTime.ToString("MM.dd.yyyy HH:mm:ss");
         }
0
 
LVL 2

Expert Comment

by:Causality
ID: 24027431
Sorry I forget Now property,

This is The Correct Code :

     private void Form1_Load(object sender, EventArgs e)
        {
             label1.Text=DateTime.Now.ToString("MM.dd.yyyy HH:mm:ss");
         }
0
 
LVL 3

Expert Comment

by:dipakdave1983
ID: 24028171
if u want to gt date of client i.e indian user can see date like GMT+530.  then render date in javascrilt.

 at the end of html markup of your page  do like.

 document.getElementById('<%# label1.ClientID %>').value=getdate();    

NOTE: // getDate() is what I  mean by javascript function i dont have it hendy.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:kieranlarkin
ID: 24028276
Thanks Guys but I was looking for a solution in VB for ASP.Net....if you can help me with that I'd appreciate it.
0
 
LVL 3

Expert Comment

by:dipakdave1983
ID: 24028915
what i have suggested doesnt matter about language. thats in markup so no language
0
 

Accepted Solution

by:
kieranlarkin earned 0 total points
ID: 24030612
In your VB codefile:

Select the Page Events Class THEN select the LoadComplete event handler

Then by using the Format() and Now() functions within this section and assinging it to the text element of your label you will display the current date and time in whatever datetime format you need as in the example below:
    Private Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
        MyVariable.Text = Format(Now(),"HH:mm")
    End Sub

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

829 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