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
Printable View
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
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:
But I don't think that this is what you mean, is it?Code:Me.Label15.Text = DateTime.Now.ToString()
Gary
like this?
vb Code:
<asp:Label ID="Label15" runat="server" Text='<%= DateTime.Now.ToString() %>' />
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
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
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????
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
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:check:
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
Hey savior14,
Have a look at this article here:
http://www.codeguru.com/vb/gen/vb_mi...le.php/c14739/
Specifically page 4.
Gary
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.
and which sometimes much longer. what would be your suggestion for that?Code:$get('<%= insideControl.ClientID %>')
$get('ctl01_tabContainer1_tc1tabpanel1_ctl02_tabContainer2_tc2tabpanel2_insideControl')
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
:D thanks Gary. yep, that make sense.
Good stuff :)