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 in any other page's page load method.
Here is my code.
HiddenField hdnCurrentDate = (HiddenField)this.Master.FindControl("hdnCurrentDate");
ClientScript.RegisterClientScriptBlock(this.GetType(), "Message", "var CurrentDate = new Date(); $('#" + hdnCurrentDate.ClientID + "').val(CurrentDate);alert($('#ctl00_hdnCurrentDate').val());", true);
I have defined Hiddenfield in master page like
<asp:HiddenField ID="hdnCurrentDate" runat="server" />
I got the alert of "hdnCurrentDate" is undefined. This is because I wrote the code in page load in not post back method.
Here is the other way what I have implemented.
I have used ConvertTimeBySystemTimeZoneId in code behind. Here is the code for the same.
DateTime ClientDateTime = DateTime.Now;
DateTime _localTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(ClientDateTime, "Arab Standard Time");
return _localTime;
I didn't get destination time zone ID instead of "Arab standard Time". If I will get it, my problem will be solved.
Is there any other way to get the current date time in any of my page. I don't want to use Session and cookies.
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…