Here are some source code to pass DateTime JavaScript value to ASP.NET in C#. It is used to get client side date and time. It is useful for those who need to display client date and time instead of hosting server date and time.
Put these codes at HTML
<input type=”hidden” id=”hdClient” runat=”server” />
Put these codes at ASP.NET code behind
At Page_Load
Page.RegisterClientScriptBlock(”1″,
“<script type=’text/javascript’>
function goforit()
{var now = new Date();
var offset = now.getTimezoneOffset();
document.forms[0].hdClient.value = -offset}
</script>”);ClientScriptManager manager = Page.ClientScript;
manager.RegisterStartupScript(this.GetType(), “CallSomething”, “goforit();”, true);
And…
Label1.Text =
DateTime.Now.ToUniversalTime().AddMinutes(double.Parse(Request.Form[”hdClient”])).ToString();
Hope this will help. ![]()
Tags: ASP.NET, C#, javascript
4 Responses
Inna
February 26th, 2008 at 4:05 am
1Thanks for the good tips
Jayce
February 26th, 2008 at 9:24 am
2You are most welcome, Inna.
senthil
December 22nd, 2008 at 2:09 pm
3Thanks.
Very useful for me….
Jayce
December 22nd, 2008 at 2:11 pm
4No problem.
RSS feed for comments on this post · TrackBack URI
Leave a reply
Categories
Archives
Chat Chat Chat...
SP Blogger
Isabell Online Penang Florist