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
446 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now