How do I clear a RadMaskedTextBox?

3 posts, 0 answers
  1. Joel
    Joel avatar
    11 posts
    Member since:
    Dec 2010

    Posted 14 Feb 2011 Link to this post

    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. Vladislav
    Admin
    Vladislav avatar
    277 posts

    Posted 16 Feb 2011 Link to this post

    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
  3. Joel
    Joel avatar
    11 posts
    Member since:
    Dec 2010

    Posted 16 Feb 2011 Link to this post

    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
Back to Top