Compatibility with MaskedEditExtender?

Mar 20, 2008 at 5:18 AM
I am using a FormView that is databound. One of the fields is a textbox that displays a date. The bound data is in the format 'dd/MM/yyyy HH:mm:SS AM', so I use a MaskedEditExtender to automatically transform the display to 'dd/MM/yyyy'.

Now to set the displayed page with no modifications on this textbox I do a SaveChanges in the FormView DataBound procedure. However the MaskedEditExtender makes a change when transforming the displayed date after this procedure, and makes the page 'Dirty'. You can visably see the time component display and then the MaskEditExtender 'kicks in' and transforms the date to take away the time component.

Can you suggest when/where I should call the SaveChanges to set the display of the page with no modifications?

My method has worked well on 2 other FormView pages, but this is the first time I have encountered the MaskedEditExtender with the ModWatchExtender.

Mar 21, 2008 at 5:16 AM
I think the cause of the problem is that the MaskedEditExtender changes the value of the TextBox on the client, not on the server. So no matter when you call SaveChanges, the TextBox will contain the full date/time.
It is only when the page loads on the client that the value of the TextBox is changed to display the desired format.

You can apply a format to the bound data to make sure the data that is bound to the TextBox is in the format required by the MaskedEditExtender:

<asp:FormView runat="server">
        <asp:TextBox Text='<%# Bind("DATE", "{0:MM/dd/yyyy}") %>' ID="txtDate" runat="server"></asp:TextBox>
        <ajax:MaskedEditExtender Mask="99/99/9999" TargetControlID="txtDate" runat="server"></ajax:MaskedEditExtender>
Mar 24, 2008 at 11:19 PM
Yes, that makes sense to me. I have employed your suggestion and it allows ModWatch to function properly.

Thanks again.