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
485 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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