ASP.NET AJAX工具包 - CalendarExtender上回发复位 [英] ASP.NET AJAX Toolkit - CalendarExtender is reset on Postback

查看:255
本文介绍了ASP.NET AJAX工具包 - CalendarExtender上回发复位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an ASP.NET page that has two input elements:


  1. 一个文本框是只读的。这个文本框是一个CalendarExtender
  2. 的TargetControl
  3. 用的AutoPostBack一个DropDownList =真

  1. A TextBox that is ReadOnly. This TextBox is the TargetControl of a CalendarExtender
  2. A DropDownList with AutoPostBack=true

下面是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:&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的回发,通过与日期选择与用户选择的日期被重置为当前的日期。另外,如果我看着文字框的Text属性,它等于的String.Empty。

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.

我如何在用户回发选择preserve日期?

How do I preserve the date that the user selected on a PostBack?

推荐答案

这是文本框读取实际上只是似乎是造成这个问题。我不使用code中的任何约束的事件重复你的问题,以及日期仍然失踪。然而,当我改变了文本框只读=假,它工作得很好。你需要有文本框为只读,或者您可以禁用它或验证的日期被输入?

The fact that the text box is read only appears to be causing this problem. I duplicated your problem using no code in any of the bound events, and the date still disappeared. However, when I changed the text box to ReadOnly=False, it worked fine. Do you need to have the textbox be read only, or can you disable it or validate the date being entered?

编辑:行,我也为你找出答案。据这个论坛的问题,只读控件不回发到服务器。所以,当你做一回发,你将失去一个只读的控制值。您将需要不使只读控制。

OK, I have an answer for you. According to this forum question, read only controls are not posted back to the server. So, when you do a postback you will lose the value in a read only control. You will need to not make the control read only.

这篇关于ASP.NET AJAX工具包 - CalendarExtender上回发复位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆