RadMaskedTextInput ValueChanged event doesn't fire

4 posts, 0 answers
  1. Mykhaylo
    Mykhaylo avatar
    3 posts
    Member since:
    Sep 2010

    Posted 10 Feb 2012 Link to this post

    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
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 15 Feb 2012 Link to this post

    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 >>
  3. DevCraft banner
  4. Mykhaylo
    Mykhaylo avatar
    3 posts
    Member since:
    Sep 2010

    Posted 17 Feb 2012 Link to this post

    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
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 22 Feb 2012 Link to this post

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