Problem: CalendarExtender value is reset on Postback.
Solution:: If you try to get selected value from Ajax Calendar Control, you will get only the default select value that you first set it. The best way to get selected datetime value is to read value from TextBox control instead.
If you want to display default today date when page load, please set it to textbox. Following is the example code:
.aspx page
<asp:TextBox ID="txbStartDate" runat="server">
<asp:CalendarExtender ID="calStartDate" runat="server" Format="MM/dd/yyyy" Enabled="True" TargetControlID="txbStartDate">
</asp:CalendarExtender>
<asp:Button runat="server" Text="Get Start Date" ID="butGetStartDate" />
<asp:Label runat="server" Text="" ID="lblStartDate">
.cs page, form load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txbStartDate.Text = DateTime.Today.AddDays(-7).ToString("MM/dd/yyyy");
}
butGetStartDate.Click += OnGetStartDateClick;
}
.cs page, Button Clicked
private void OnGetStartDateClick(object sender, EventArgs e)
{
lblStartDate.Text = txbStartDate.Text;
}
0 comments:
Post a Comment