2009-06-12 118 views
0

我目前正在開發一個需要DateTime條目的網站,並且我在用於輸入日期和時間的TextBox上使用了MaskEdit擴展器。這些日期時間被用作輸入來計算需要在同一頁面上顯示的總小時數和其他內容(用於預覽)MaskedEdit Extender在回發中丟失數據

但是,在使用MS AJAX回發之後,我的計算數據顯示但我的DateTime條目已清除。在更新到可用於.NET 2.0的最新AjaxControlToolkit之前,我的條目在回發之後已損壞。回發由LinkBut​​ton觸發。在此之前,我嘗試使用TextBox的AutoPostBack屬性。

修復的任何想法,或者我應該考慮開溝MS AJAX,並開始使用另一個用於ASP.NET的AJAX庫或直接轉到JS。

注意,由於目標服務器使用Windows 2000無法使用.NET 3.5 .....

回答

0

我不能重現此錯誤。你能發佈你的代碼嗎?

編輯:好吧,幾個可能的解決方案。

  1. 使用屬性

    ClearTextOnInvalid = 「假」

您MaskedEditExtenders。這將防止頁面無效時刪除輸入的日期。

  1. 請檢查並確認您沒有爲帶有遮罩編輯擴展器的文本框指定值,因爲如果您意外輸入了無效值,它將不會接受它,抹掉它

我發現的唯一的其他的解決辦法是不使用的MaskedEditExtender在所有...

+0

是的,我想我會忘掉這一點。謝謝 – 2009-06-12 15:10:07

+0

您是使用MaskedEditValidator控件,還是分配了EnableEventValidation =「false」? – 2011-01-12 17:43:55

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

LinkBut​​ton的守則的UpdatePanel內的用戶控件的一部分:

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 
    }