How to set Today’s Date by TimeZone to Ajax CalenderExtender


Code in .aspx:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function clientShowing(sender, args) {
if (new Date($get("HiddenField1").value) != null) {
sender.set_todaysDate(new Date($get("HiddenField1").value));
}
}
</script>
</head>
<body>
<form id="form2" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:calendarextender ID="CalendarExtender1" runat="server" Enabled="True" Format="dd/MM/yyyy"
TargetControlID="TextBox1" OnClientShowing="clientShowing"
PopupPosition="BottomLeft">
</asp:calendarextender>
<asp:HiddenField ID="HiddenField1" runat="server" />

</div>
</form>
</body>
</html>

Code in .aspx.cs:

           using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HiddenField1.Value =
(TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow,
TimeZoneInfo.FindSystemTimeZoneById("Tonga Standard Time"))).ToString();
    }
}

Advertisements