Display Server Datetime Clock [Resolved]

Posted by Bugwee under ASP.NET on 4/17/2011 | Points: 10 | Views : 7352 | Status : [Member] | Replies : 5
hello everybody,

i able to display a clock on client pages but it only displays their local datetime. Is this possible that i could retrieve and display a clock on client pages with the server datetime? if possible, i want some any ideas...

thanks,

Bugwee




Responses

Posted by: Ndebata on: 4/18/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi

You can use ajax forthis.
In you aspx file
<asp:ScriptManager ID="ScriptManager1" runat="server" >

</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
<asp:Timer ID="Timer1" Interval="1000" runat="server" >
</asp:Timer>


and in your code behind file

protected override void OnInit(EventArgs e)

{
base.OnInit(e);
Timer1.Tick += new EventHandler<EventArgs>(Timer1_Tick);
}

void Timer1_Tick(object sender, EventArgs e)
{
Label2.Text = DateTime.Now.ToLongTimeString();
UpdatePanel1.Update();
}


Thanks,
Debata

Bugwee, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Walia_jagwinder on: 4/17/2011 [Member] Starter | Points: 25

Up
0
Down
On Page load u can get the server time

datetime.now();

One person's data is another person's program.

Bugwee, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bugwee on: 4/17/2011 [Member] Starter | Points: 25

Up
0
Down
hi Walia_jagwinder,

thanks for your response but i have tried it yesterday using this one below.

var serverDateTime =  DateTime.Now;


i able to display the server datetime but i want the clock to tick.. although what i want is not usable but I'm just curious with this.

Bugwee, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bugwee on: 4/18/2011 [Member] Starter | Points: 25

Up
0
Down
hi Ndebata,

it works. i just did it on vb.net.

 Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Label2.Text = DateTime.Now.ToLongTimeString()
UpdatePanel1.Update()
End Sub


Thanks




Bugwee, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 4/18/2011 [Member] Starter | Points: 25

Up
0
Down
Thank you sir
Debata

Bugwee, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response