I have a hidden field in my master page. And I set the current date and time as a value in that \"hiddenfield\" using Javascript. I am unable to get this hidden field value
I have done this by using following way:
I have taken a HiddenField
into the previous page where it requires :
Then, I am getting browser timezone by this :
$(document).ready(function () {
var offset = new Date().getTimezoneOffset();
$('#hdnTimeOffset').val(offset);
});
I am getting time zone into a Session
variable of the previous page, before redirecting to the next page, like on button click:
protected void btn_Click(object sender, EventArgs e)
{
Session["TimeOffset"] = hdnTimeOffset.Value;
Response.Redirect("~/Root/abc.aspx");
}
In the Main Page, I get the current time by using following code :
DateTime dtmCurrentDateTime = DateTime.Now.ToUniversalTime();
double dblMinutes =Convert.ToDouble(Session["TimeOffset"].ToString());
dtmCurrentDateTime = dtmCurrentDateTime.AddMinutes(-dblMinutes);