Pass DateTime JavaScript value to ASP.NET C#

Pass DateTime JavaScript value to ASP.NET C#


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
“<script type=’text/javascript’>
function goforit()
{var now = new Date();
var offset = now.getTimezoneOffset();
document.forms[0].hdClient.value = -offset}

ClientScriptManager manager = Page.ClientScript;
manager.RegisterStartupScript(this.GetType(), “CallSomething”, “goforit();”, true);


Label1.Text =

Hope this will help. :D

  • Inna

    Thanks for the good tips

  • Jayce

    You are most welcome, Inna. :D

  • http://- senthil


    Very useful for me….

  • Jayce

    No problem. ;)

  • Dave

    Thanks for the pointer, Is there a semi-colon missing on the last statement?
    Also, in asp I am having trouble assigning the value. Would i see the value of the hidden input in the value section? furthermore, can you access the value in c# via Label1.Text=hdClient.Value; ?