我目前正在开发一个需要DateTime输入的网站,我在用于输入日期和时间的TextBox上使用MaskEdit扩展程序。这些DateTime用作输入以计算需要在同一页面上显示的总小时数和其他内容(用于预览)
然而,在使用MS AJAX回发后,我的计算数据显示但我的DateTime条目清除。在我更新到可用于.NET 2.0的最新AjaxControlToolkit之前,我的条目在回发后被破坏了。回发由LinkButton触发。在此之前,我尝试使用TextBox的AutoPostBack属性。
任何修复的想法,或者我应该考虑放弃MS AJAX并开始使用另一个AJAX库用于ASP.NET或直接转向JS。
请注意,我无法使用.NET 3.5,因为目标服务器使用的是Windows 2000 .....
答案 0 :(得分:0)
我无法重现此错误。你能发贴你的代码吗?
编辑:好的,有几种可能的解决方案。
使用属性
ClearTextOnInvalid = “假”
。如果页面无效,这将阻止页面删除输入的日期。
我发现的唯一其他解决方案是根本不使用MaskedEditExtender ......
答案 1 :(得分: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>
这只是一个样本,其余的非常相似。这是UserControl的一部分,它包含在MS AJAX的UpdatePanel中
LinkButton代码:
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
}