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.
I sorted it by creating a Keywords_Loaded void. I was then able to use the values passed in from the previous form.