Use response value in child window

和自甴很熟 提交于 2019-12-13 08:58:22

问题


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:


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



来源:https://stackoverflow.com/questions/10516377/use-response-value-in-child-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!