lundi 29 juin 2015

Xamarin: How to prevent navigation to another page until web-service responds


I try to call the web-service to retrieve the data for displaying in the next page. But, page is trying to display(empty data) before finishing the web-service request. Can you please help me with this.

//code


            var tapGestureRecognizer = new TapGestureRecognizer();
             tapGestureRecognizer.Tapped += async (s, e) =>
             {

            getEmployeepage(mainContact.managerID);                 
            await Navigation.PushAsync(new ManagerDetailsPage(data()));

             };
             manager.GestureRecognizers.Add(tapGestureRecognizer);

//method for retrieving the data

public async void getEmployeepage(String searchvalue)
        {
            EmployeeDetailsPage employeeDetailsPage = null;
            try
            { 

                var client = new System.Net.Http.HttpClient();

                client.BaseAddress = new Uri("http://..........");
                var response = await client.GetAsync("criterion?empId=" + searchvalue);
                string jsonString = response.Content.ReadAsStringAsync().Result;


    //rest of the logic              

}


}

Thanks in Advance.


Aucun commentaire:

Enregistrer un commentaire