Search code examples
c#silverlight-4.0childwindow

Duplicating Child Window problem


In my application I have a Submit button that does this:

private void Submit_button_Click(object sender, RoutedEventArgs e)
{
    string variable = variable_textBox.Text;
    if (variable.Length >= 1 && variable.Length <= 6)
    {
        //get some data from db
    }
    else
    {
        ChildWindow msg = new Msg("Some string");
        msg.Show();
    }
}

Here is my problem:

When I write a string so that the program goes to the else clause, a childWindow will appear (that is OK); but if I do this again, 2 childWindows will appear. For each click on Submit button, I get num of clicks childWindows.

Can someone tell me why? I use the same ChildWindow in other places, and I have no problems...


Solution

  • Seems like Submit_button_Click method is being attached multiple times to the click event (for each click).

    Make sure this is not the case by putting a breakpoint in there and see if it is hit multiple times.