Forum Discussion
radov
Staff
15 years agoHi 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:
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:
I hope this information helps you. Also, to learn more about simulating keystrokes, please see the Simulating Keystrokes help topic.
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.