ASP.NET AJAX工具包 – CalendarExtender在Postback上重置

我有一个ASP.NET页面有两个输入元素:

> ReadOnly的TextBox.此TextBox是CalendarExtender的TargetControl
>具有AutopostBack = True的DropDownList

这是代码

<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:&nbsp;</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>

当DropDownList发回时,用户使用datePicker选择的日期将重置为当前日期.另外,如果我查看dateTextBox的Text属性,它等于string.Empty.

如何保留用户在PostBack上选择的日期?

解决方法

文本框是只读的事实似乎是导致这个问题.我在任何绑定的事件中使用任何代码复制了你的问题,而日期仍然消失.但是,当我将文本框更改为ReadOnly = False时,它工作正常.您需要将文本框设为只读,还是禁用它或验证输入的日期?

编辑:好的,我有一个答案.根据to this forum question,只读控件没有发回到服务器.所以,当你做一个回发,你将失去一个只读控件的价值.您将不需要只读控件.

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...