Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
492 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 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