This is a migrated thread and some comments may be shown as answers.

How do I clear a RadMaskedTextBox?

2 Answers 82 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Joel asked on 14 Feb 2011, 05:18 PM
Hi,

I'm having a heck of a time trying to clear a Silverlight RadMaskedTextBox control.  What I want to do is iterate through a list of values to type into the control using the WebAii framework.  After typing a value, I would like to clear the control and then type the next value.  Here's what I have so far:

            theControl.MouseClick(MouseClickType.LeftClick, 0, true);
            theControl.TypeText(textToType, 0);

With this code, its appending the new value to what's currently there.  I've looked for a few hours and haven't found anything on clearing the control.

Thanks for your help.

Joel

2 Answers, 1 is accepted

Sort by
0
Vladislav
Telerik team
answered on 16 Feb 2011, 09:56 AM
Hello Joel,

Thank you for your feedback.
Actually there is no easy way to clear the value of the RadMaskedTextBox control using only the Web Aii framework. There is no particular method in the RadMaskedTextBox's wrapper for this particular purpose.

Anyway I can suggest you several workarounds which should help you to achieve the desired result.
1. The simplest way is just to clear "manually" the value of the RadMaskedTextBox using the Web Aii framework.
You could have something like:

theControl.MouseClick(MouseClickType.LeftClick, 0, true);
theControl.TypeText("     ", 0);
where the number of spaces in the "TypeText" method is equal to the length of your RadMaskedTextBox.
2. You can set explicitly the "Value" property of the RadMaskedTextBox to "string.Empty" or "null".
3. You can set the property of the RadMaskedTextBox control "SelectionOnFocus" to value "SelectAll". Thus anytime the RadMaskedTextBox gets the focus its content will be automatically selected and any typing in it will replace the previous content.

I hope that some of the above solutions will help you to successfully achieve your goal(s).
Please, don't hesitate to ask if you have any additional questions/comments on the subject.


All the best,
Vladislav
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Joel
Top achievements
Rank 1
answered on 16 Feb 2011, 03:12 PM
Hi Vladislav,

I sort of implemented number 2 as a solution to this problem.

I created a AutomationMethod to set focus on the control and then an AutomationProperty to allow me to change its value:

    AutomationMethod focusMethod = new AutomationMethod("Focus", typeof(bool));
    AutomationProperty valueProperty = new AutomationProperty("Value", typeof(string));

With these set up I could then do the following to clear the text box:

    radMaskedTextBox.InvokeMethod(focusMethod);
    radMaskedTextBox.SetProperty(valueProperty, string.Empty);

Thanks for your help.

Joel
Tags
General Discussions
Asked by
Joel
Top achievements
Rank 1
Answers by
Vladislav
Telerik team
Joel
Top achievements
Rank 1
Share this question
or