0

I am using Silverlight, and passing a value into a textbox in a childwindow,

the textBox1_TextChanged event should fire a webservice call that should populate a listbox on the childwindow, however for some reason when the child window loads, the text box has the value passed into it as desired, but for some reason the TextChanged event is not firing?

Is there any specific reason for this?

Here is the change event -

private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
    {
        WebService.Service1SoapClient client = new WebService.Service1SoapClient();
        client.PRSHListCompleted += new EventHandler<PRSHListCompletedEventArgs>(client_PRSHListCompleted);
        client.PRSHListAsync(System.Convert.ToInt16(textBox1.Text));

        textBox2.Text = "OK"; //I did this to test if I was getting to the event and it failed.
    }

I pass in textBox1.Text from the parent window here-

Settings set = new Settings();
set.textBox1.Text = System.Convert.ToString(PRSID);

set.Show();

Where set is the child window.

This is the XAML for the text box -

<TextBox Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="12,13,0,0" Name="textBox1" VerticalAlignment="Top" Width="28" TextChanged="textBox1_TextChanged" />
Ebikeneser
  • 2,582
  • 13
  • 57
  • 111
  • 3
    could you give us the pieces of code where you are making the event subscription? – ie. May 04 '12 at 09:41
  • Could you paste some code, primarily how the event is hooked up and how the value is passed to the text box. – Lukazoid May 04 '12 at 09:41
  • ok, that is great now we could see event handler and text change code, but what about the code where you are making the event subscription? – ie. May 04 '12 at 09:52
  • Could you explain event subscription please? – Ebikeneser May 04 '12 at 09:56
  • set.textBox1 += textBox1_TextChanged; (in C# code) or (in XAML) – ie. May 04 '12 at 09:59
  • Im not sure but there is an update? – Ebikeneser May 04 '12 at 10:03
  • yep, everything looks good. "TextChanged event is not firing" - try to set the brakepoint in the very beginning of the textBox1_TextChanged method and let us know if it fires – ie. May 04 '12 at 10:27
  • I've suggested this (my comment above), as you may have an exception in the code before 'textBox2.Text = "OK"' – ie. May 04 '12 at 10:35
  • Yep I have tried putting a break point there, the changed event does not fire, suggesting that it isn't being invoked? Does this mean that the text isn't changing? Even though I can see the value on the child window? Its odd. – Ebikeneser May 04 '12 at 10:40
  • ohh, I've been able to reproduce it. I'll let you know, if I could figure out why the behaviour is so. – ie. May 04 '12 at 10:54

1 Answers1

1

You can set the textBox1.Text right after the Settings.Loaded event is fired and all XAML event subscriptions are made.

So try this one:

Settings set = new Settings();
set.Loaded += (o, args) =>
{
    //set.Dispatcher.BeginInvoke(() =>
    //{
    set.textBox1.Text = System.Convert.ToString(PRSID);
    //});
};

set.Show();
ie.
  • 5,982
  • 1
  • 29
  • 44
  • Its odd, this worked once, but trying it again it fails? If I manually delete and then type in the PRSID once the form has loaded, this fires the textBox-Changed event and the value updates the lstbox. Any other suggestions? – Ebikeneser May 04 '12 at 11:53
  • I've updated my code. if you uncomment the new code, everything should be fine, _but_ I'm still not sure why it is not stable without the new code. I'll try to figure out what is the problem and , if I find something, I'll let you know – ie. May 04 '12 at 13:30
  • You got it! If I may ask for an explanation of why this method works please? I take it is force clearing the form then updating? Really appreciate. – Ebikeneser May 04 '12 at 13:37
  • I am no trying to use the values in the textBox in the initialise component section of the set child window, however it is saying they are null? How can I solve this? – Ebikeneser May 09 '12 at 14:17
  • sorry, I don't get it. could you please throw me a piece of code? – ie. May 09 '12 at 14:25