0

我目前正在开发一个需要 DateTime 输入的网站,并且我在用于输入日期和时间的 TextBox 上使用 MaskEdit 扩展器。这些 DateTime 用作输入来计算需要在同一页面上显示的总小时数和其他内容(用于预览)

但是,在使用 MS AJAX 回发后,我的计算数据会显示,但我的 DateTime 条目会清除。在我更新到可用于 .NET 2.0 的最新 AjaxControlToolkit 之前,我的条目在回发后已损坏。回发由 LinkBut​​ton 触发。在此之前,我尝试使用 TextBox 的 AutoPostBack 属性。

任何关于修复的想法,或者我应该考虑放弃 MS AJAX 并开始使用另一个 AJAX 库用于 ASP.NET 或直接使用 JS。

请注意,我不能使用 .NET 3.5,因为目标服务器使用的是 Windows 2000 .....

4

2 回答 2

0

我无法重现此错误。你能发布你的代码吗?

编辑:好的,几个可能的解决方案。

  1. 使用属性

    ClearTextOnInvalid="假"

在您的 MaskedEditExtenders 上。如果输入的日期无效,这将防止页面删除。

  1. 检查并仔细检查您没有使用 Masked Edit Extenders 为这些文本框分配值,因为如果您不小心输入了无效值,它将不会接受并删除它

我发现的唯一其他解决方案是根本不使用 MaskedEditExtender ......

于 2009-06-12T13:46:27.470 回答
0

当然

ASPX 部分:

  <td><asp:TextBox id="textBeginStation" runat="server"></asp:TextBox></td>
<td>
    <asp:TextBox ID="textBeginServiceDateTime" runat="server"></asp:TextBox>
    <ajaxToolkit:MaskedEditExtender
        ID="textBeginServiceDateTimeMaskedEditExtender" runat="server" 
        TargetControlID="textBeginServiceDateTime" MaskType="DateTime" 
        Mask="9999/99/99 99:99" UserDateFormat="YearMonthDay" 
        UserTimeFormat="TwentyFourHour">
    </ajaxToolkit:MaskedEditExtender>
</td>
<td>
    <asp:TextBox ID="textBeginStationDateTime" runat="server"></asp:TextBox>
    <ajaxToolkit:MaskedEditExtender
        ID="textBeginStationDateTimeMaskedEditExtender" runat="server" 
        TargetControlID="textBeginStationDateTime" MaskType="DateTime" 
        AutoComplete="False" Mask="9999/99/99 99:99" UserDateFormat="YearMonthDay" 
        UserTimeFormat="TwentyFourHour" EnableViewState="False">
    </ajaxToolkit:MaskedEditExtender>
</td>
<td><asp:TextBox ID="textBeginRemarque" runat="server"></asp:TextBox></td>

这只是一个示例,其余部分非常相似。这是包含在 MS AJAX 的 UpdatePanel 中的 UserControl 的一部分

链接按钮代码:

ProductionDependencyFactory depFactory = new ProductionDependencyFactory();
    try
    {
        DateTime beginServiceDateTime = DateTime.Parse(textBeginServiceDateTime.Text);
        DateTime beginStationDateTime = DateTime.Parse(textBeginStationDateTime.Text);
        DateTime endServiceDateTime = DateTime.Parse(textEndServiceDateTime.Text);
        DateTime endStationDateTime = DateTime.Parse(textEndStationDateTime.Text);

        NormalTrainTimeMilageCalculator calculator = depFactory.Create<NormalTrainTimeMilageCalculator>();

        calculator.BeginStation = textBeginStation.Text;
        calculator.BeginServiceDateTime = beginServiceDateTime;
        calculator.BeginStationDateTime = beginStationDateTime;
        calculator.EndStationDateTime = endStationDateTime;
        calculator.EndServiceDateTime = endServiceDateTime;
        calculator.EndStation = textEndStation.Text;

        labelTotalHour.Text = calculator.TotalTime().Hours.ToString();
        labelTotalMinute.Text = calculator.TotalTime().Minutes.ToString();
        labelTotalMilage.Text = calculator.TotalMilage().ToString();
    }
    catch (Exception)
    {
        // Do nothing
    }
于 2009-06-12T14:15:44.077 回答