|
-
Jul 20th, 2010, 04:57 AM
#1
Thread Starter
Lively Member
How to assign system time(now()) to label in ASP.net ???
Hi,
How to assign system time(now()) to label, while webpage loading itself in asp.net.
Ex:
<asp:Label ID="Label15" runat="server" Text=></asp:Label>
Regards,
Nagu
-
Jul 20th, 2010, 06:30 AM
#2
Re: How to assign system time(now()) to label in ASP.net ???
Hey,
I am not sure that I follow exactly what you are saying?
While the page is "loading" you can't really interact with the page, it is only once the page has "loaded" that the user will be able to see the text that you put onto the page. i.e. in the Page_Load event, you could do something like:
Code:
Me.Label15.Text = DateTime.Now.ToString()
But I don't think that this is what you mean, is it?
Gary
-
Jul 20th, 2010, 07:53 PM
#3
Lively Member
Re: How to assign system time(now()) to label in ASP.net ???
like this?
vb Code:
<asp:Label ID="Label15" runat="server" Text='<%= DateTime.Now.ToString() %>' />
im a newbie in vb.net field so please always bear with me 
-
Jul 20th, 2010, 11:57 PM
#4
Thread Starter
Lively Member
Re: How to assign system time(now()) to label in ASP.net ???
-
Jul 21st, 2010, 01:08 AM
#5
Re: How to assign system time(now()) to label in ASP.net ???
 Originally Posted by rnjnagu
no its not working.
Give us a clue here, why exactly isn't it working?
I can tell you for certain, that the code that I posted does exactly what I said it does. i.e. when the page opens, it displays the time at the point when the page was loaded.
If this is not what you want to happen, you need to tell us exactly what you want.
Gary
-
Jul 21st, 2010, 01:10 AM
#6
Re: How to assign system time(now()) to label in ASP.net ???
 Originally Posted by savior14
like this?
vb Code:
<asp:Label ID="Label15" runat="server" Text='<%= DateTime.Now.ToString() %>' />
Savior14, although this will work, you are mixing the ASPX markup with server side code, which although works, and has it's uses, does involve a slight amount of overhead to process, and I would recommend that you don't do it, unless you have to.
In this case, the work can easily be done of the server.
Gary
-
Jul 21st, 2010, 01:28 AM
#7
Thread Starter
Lively Member
Re: How to assign system time(now()) to label in ASP.net ???
Hi Gary,
Your following code looks VB.net,
Me.Label15.Text = DateTime.Now.ToString()
But i dont know how to implement this in ASP.net????
-
Jul 21st, 2010, 01:49 AM
#8
Re: How to assign system time(now()) to label in ASP.net ???
ASP.Net is the framework that you build your Web Application on. Using that Framework you then have the option to use either VB.Net or C# to write the server side code for the web application.
Have you tried the example that I have gave?
Gary
-
Jul 21st, 2010, 02:00 AM
#9
Thread Starter
Lively Member
Re: How to assign system time(now()) to label in ASP.net ???
Great!! I forgot about page load concept in code behind.
Now, its working well.
Corrected Solution:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Label15.Text = DateTime.Now.ToString("dd/MM/yyyy")
End Sub
-
Jul 21st, 2010, 02:03 AM
#10
Re: How to assign system time(now()) to label in ASP.net ???
That's the one!!
The development paradigm is definitely different in ASP.Net Applications, but you will soon get the hang of it.
Remember to mark your thread as resolved using the thread tools.
Gary
-
Jul 21st, 2010, 09:23 PM
#11
Lively Member
Re: How to assign system time(now()) to label in ASP.net ???
 Originally Posted by gep13
Savior14, although this will work, you are mixing the ASPX markup with server side code, which although works, and has it's uses, does involve a slight amount of overhead to process, and I would recommend that you don't do it, unless you have to.
In this case, the work can easily be done of the server.
Gary
ohh.. I thought that's what he was asking for =)
are there any complication on mixing aspx markup with server side codes?
can you site a scenario? thanks!
im a newbie in vb.net field so please always bear with me 
-
Jul 22nd, 2010, 12:51 AM
#12
Re: How to assign system time(now()) to label in ASP.net ???
Hey savior14,
Have a look at this article here:
http://www.codeguru.com/vb/gen/vb_mi...le.php/c14739/
Specifically page 4.
Gary
-
Jul 22nd, 2010, 02:21 AM
#13
Lively Member
Re: How to assign system time(now()) to label in ASP.net ???
I got your point there. But what if in-case of using it on javascript? searching for a control which is inside of multiple tabcontainer/tabpanels? that would be a hassle to hardcode the ID just to find that control.
ie.
Code:
$get('<%= insideControl.ClientID %>')
$get('ctl01_tabContainer1_tc1tabpanel1_ctl02_tabContainer2_tc2tabpanel2_insideControl')
and which sometimes much longer. what would be your suggestion for that?
im a newbie in vb.net field so please always bear with me 
-
Jul 22nd, 2010, 02:29 AM
#14
Re: How to assign system time(now()) to label in ASP.net ???
In these type of situations, I would do the work on the server to prepare the JavaScript, and then inject it onto the page. That way, the ClientID property is available at the time the JavaScript is being created, and then only the fully qualified ID is rendered to the client.
Does that make sense?
Gary
-
Jul 22nd, 2010, 02:37 AM
#15
Lively Member
Re: How to assign system time(now()) to label in ASP.net ???
thanks Gary. yep, that make sense.
im a newbie in vb.net field so please always bear with me 
-
Jul 22nd, 2010, 02:38 AM
#16
Re: How to assign system time(now()) to label in ASP.net ???
Good stuff
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|