Use response value in child window

2019-09-21 17:49发布

I am having difficulty getting to grips with how Silverlight uses asynchronous responses from a web service. I have declared-

public partial class Users : Page
{
    public string PID;

and then use-

 if
 {
 WebService.Service1SoapClient client = new WebService.Service1SoapClient();
 string profile = System.Convert.ToString(((ListBoxItem)listBox1.SelectedItem).Content);
 client.pidReturnCompleted += new EventHandler<pidReturnCompletedEventArgs>(client_pidReturnCompleted);
 client.pidReturnAsync(USERID, profile);
 }
 Else
 {

 KeyWords keywords = new KeyWords();

 keywords.textBox3.Text = PID;
 keywords.Show();

Where PID-

void client_pidReturnCompleted(object sender, pidReturnCompletedEventArgs e)
    {
        PID = e.Result;
    }

I then need to use this PID in the Initialise Component section of the Keywords child window, however when the window loads, it does not get the textBox.Text (the PID value) in time, and says it is null. How can I use the PID in the Initialise Component stage? So in the Keywords window-

public KeyWords()
    {
        InitializeComponent();

        this.Loaded += new RoutedEventHandler(KeyWords_Loaded);

        WebService.Service1SoapClient client = new WebService.Service1SoapClient();
        client.userKeywordsCompleted += new EventHandler<userKeywordsCompletedEventArgs>(client_userKeywordsCompleted);
        client.userKeywordsAsync(PID);

    }

Where- Public Int PID = textBox3.Text //this is where the value from the previous window is passed in.

1条回答
在下西门庆
2楼-- · 2019-09-21 18:12

I sorted it by creating a Keywords_Loaded void. I was then able to use the values passed in from the previous form.

查看更多
登录 后发表回答