Forum Discussion

jlivengood's avatar
jlivengood
Occasional Contributor
15 years ago

Issue with Ajax Masked Extender Control

We have a date of birth box where we use an Ajax extender to help make sure the date is entered correctly. See the .aspx markup below..



  <asp:TextBox ID="DOBTextBox" runat="server" Text='<%# Eval("DOB") %>' TabIndex="5"/>

                        <cc1:MaskedEditExtender ID="DOBMaskedEditExtender" runat="server"

                            ClearTextOnInvalid="true" Mask="99/99/9999" MaskType="Date"

                            TargetControlID="DOBTextBox">

                        </cc1:MaskedEditExtender>



   When I run my scripts I see the date entered but when the text box control is clicked off of, (The user clicks the next text box in the form..) the    text that has been entered goes away. Is there a way that anybody knows of to get the textbox to retain its value. Below is my code from the script. FindChildByName is simply a method I use to find the box. Any help or suggestions would be greatly appreciated.



Jason



var dobtext = FindChildByName('["Textbox"]("ctl00_ctl00_ctl00_BodyLoginView_BodyPlaceHolder_LoggedInBody_UploadBodyContext_AddLocatePatientCtrl_AddLocatePatientInfo_EditFormView_DOBTextBox")') ;


dobtext["SetText"]("03031975");

1 Reply

  • Hi Jason,



    The MaskedEditExtender element in your code has the ClearTextOnInvalid attribute set to true. It specifies that the appropriate text box will be cleared after moving the focus from the box if the entered value is considered as invalid by MaskedEditExtender. It seems that the value you entered to the box with the SetText method is considered as invalid. A valid date value that matches the specified mask must contain the day, month and year values separated by slash symbols ('/'). However, it seems that slash symbols are automatically inserted by the control after the day and month parts of the date when you manually type the value into the box. Therefore, to enter a date value like "03/03/1975" to the box, you normally type only "03031975".



    However, when you set a new value to the text box by calling the SetText method, the latter changes the text in the box programmatically. In this case, it is possible that some events that check the value being entered into the box and that automatically add slash symbols are not raised in the application. Therefore, a value like "03031975" set by the SetText method remains the same (with no slashes) and is considered as invalid upon changing the focus. In this case, I recommend that you try to specify full date values with slash delimiters when calling the SetText method. I think, such values should be considered as valid, and the text box will not be cleared. For instance:





    dobtext["SetText"]("03/03/1975");





    If this solution does not work for you, please try to use the Keys action instead of SetText. The Keys action enters the specified text into the box by simulating the pressing of the appropriate keys. In this case, the tested application automatically checks the value being entered and adds slash delimiters as if you manually typed the value. Therefore, you don't need to pass slash symbols to the Keys method when calling it:





    dobtext["Keys"]("03031975");





    I hope this information helps you. Also, to learn more about simulating keystrokes, please see the Simulating Keystrokes help topic.