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

RadMaskedTextInput ValueChanged event doesn't fire

3 Answers 368 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mykhaylo
Top achievements
Rank 1
Mykhaylo asked on 10 Feb 2012, 12:06 PM
Hello,
I encountered the next bug: when I set the Value property of RadMaskedTextInput programmatically, the ValueChanged event doesn't fire. I'm using Silverlight 5 and 2011 Q3 controls with dll version number 2011.3.1220.1040. A mock project to reproduce this contains only the main page:
<UserControl x:Class="SilverlightMock.MainPage"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
     
    <StackPanel x:Name="LayoutRoot" Background="White">       
        <Button Content="Click" Click="Button_Click" />
        <telerik:RadMaskedTextInput x:Name="Box" />
    </StackPanel>
</UserControl>
and codebehind file:
using System;
using System.Windows;
using System.Windows.Controls;
 
namespace SilverlightMock
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var box = this.Box;
            box.ValueChanged += box_ValueChanged;
            box.Value = "111";
            box.Value = "222";
            box.Value = "333";
        }
 
        void box_ValueChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            throw new Exception();
        }
    }
}
The exception will be never thrown (nor breakpoint hit if set there). But if you first click and then type some text in the view, the exception will be thrown, so the ValueChanged event is fired normally.
This results in the fact I can't create a unit test for my custom controls using RadMaskedTextInput. Or should I use some other way to simulate user input to the RadMaskedTextInput control?
Thanks,
Mykhaylo

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 15 Feb 2012, 02:07 PM
Hello Mykhaylo,

The RadMaskedTextInput.ValueChanged event is only fired after a user-triggered action. As changing the value of the control in code-behind isn't considered a user-triggered interaction, the event handler is never executed.

If in your unit tests you need to make sure that the value of the control is properly updated, then a possible approach is to check if the RadMaskedTextInput.Text property is updated accordingly to the new value as soon as you set it.

Please give this a try and let me know if it works for you.

Greetings,
Tina Stancheva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Mykhaylo
Top achievements
Rank 1
answered on 17 Feb 2012, 12:22 PM
The problem was that I subscribed to ValueChanged within the control (to make a validation check of the input), and it didn't work after Value changed programmatically. I just added an extra layer of methods to handle this out (like void InputText(string) with setting value and calling the same method that reacts on the event ValueChanged), made them internal and added InternalsVisibleTo the test project, so I can simulate user input correctly. Just instead of some EventArgs I needed to use their components (e.g. Key pressed) because I cannot create an instance of these EventArgs. I cannot use Text property as it is affected with Mask (actually, I can check if it is correctly rendered, but I never had problems with this).

Mykhaylo
0
Tina Stancheva
Telerik team
answered on 22 Feb 2012, 10:57 AM
Hello Mykhaylo,

I am glad that you found a way to work around the issue. If you encounter any other issues or have more questions on the controls, please let us know.

Kind regards,
Tina Stancheva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Mykhaylo
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Mykhaylo
Top achievements
Rank 1
Share this question
or