views:

1099

answers:

2

I am currently developping an web site that require DateTime entry and I am using MaskEdit extender on the TextBox used to enter the date and time. These DateTime are used as input to compute the total hours and other stuff that need to be displayed back on the same page (for previewing)

However, after the postback using MS AJAX, my computed data shows but my DateTime entries clears. Before I updated to latest AjaxControlToolkit available for .NET 2.0, my entries was corrupted after the postback. The postback is triggered by a LinkButton. Before that I tried using AutoPostBack property of TextBox.

Any ideas for a fix or should I consider ditching MS AJAX and start using another AJAX library either for ASP.NET or going to JS directly.

Note that I can't use .NET 3.5 because the target server is using Windows 2000.....

A: 

I cannot reproduce this error. Could you post your code?

EDIT: Ok, couple of possible solutions.

  1. Use the attribute

    ClearTextOnInvalid="false"

on your MaskedEditExtenders. This will prevent the page from erasing the entered date if it is invalid.

  1. Check and double check that you are not assigning a value to those text boxes with the Masked Edit Extenders, since if you accidentally put in an invalid value, it will not accept it and erase it

The only other solution I have found is to not use the MaskedEditExtender at all...

Matthew Jones
Yeah, I think I will just forget this. Thanks
Michaël Larouche
A: 

Sure

ASPX part:

  <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>

This is just a sample, the rest is pretty similar. This is part of a UserControl that gets included inside a UpdatePanel from MS AJAX

The LinkButton Code:

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
    }
Michaël Larouche
Also note that the globalisation culture is set to fr-CA
Michaël Larouche