ASP.NET AJAX Toolkit - CalendarExtender is reset on Postback
Posted
by user70192
on Stack Overflow
See other posts from Stack Overflow
or by user70192
Published on 2009-06-05T17:33:28Z
Indexed on
2010/04/05
14:43 UTC
Read the original article
Hit count: 895
ASP.NET
|calendarextender
Hello,
I have an ASP.NET page that has two input elements:
- A TextBox that is ReadOnly. This TextBox is the TargetControl of a CalendarExtender
- A DropDownList with AutoPostBack=true
Here is the code:
<table border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="2">Date:</td></tr>
<tr><td colspan="2">
<asp:TextBox ID="dateTextBox" runat="server" ReadOnly="true" />
<ajax:CalendarExtender ID="datePicker" runat="server" Format="MM/dd/yyyy" OnLoad="datePicker_Load" TargetControlID="dateTextBox" />
</td></tr>
<tr><td colspan="2">Select an Option:</td></tr>
<tr>
<td>Name: </td>
<td><asp:DropDownList ID="optionsDropDownList" runat="server" AutoPostBack="true"
OnLoad="optionsDropDownList_Load"
OnSelectedIndexChanged="optionsDropDownList_SelectedIndexChanged"
DataTextField="Name" DataValueField="ID" />
</td></tr>
<tr><td><asp:Button ID="saveButton" runat="server" Text="Save" OnClick="saveButton_Click" /></td></tr>
</table>
When the DropDownList posts back, the date selected by the user with the datePicker is reset to the current date. In addition, if I look at the Text property of dateTextBox, it is equal to string.Empty.
How do I preserve the date that the user selected on a PostBack?
© Stack Overflow or respective owner