加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 20:19:15 所属栏目:asp.Net 来源:网络整理
导读:我有一个ASP.NET页面有两个输入元素: ReadOnly的TextBox.此TextBox是CalendarExtender的TargetControl 具有AutoPostBack = True的DropDownList 这是代码: table border="0" cellpadding="0" cellspacing="0" trtd colspan="2"Date:/td/tr trtd colspan="2"
我有一个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,只读控件没有发回到服务器.所以,当你做一个回发,你将失去一个只读控件的价值.您将不需要只读控件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读