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,只读控件没有发回到服务器.所以,当你做一个回发,你将失去一个只读控件的价值.您将不需要只读控件.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....