Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

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()));//should execute after the above call completes.

             };
             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.

Best Answers

  • RafaelMouraRafaelMoura BRInsider, University, Developer Group Leader ✭✭✭
    Accepted Answer

    @VenkataKrishnaChikkala hey

    Try:

    //code
    
    
                var tapGestureRecognizer = new TapGestureRecognizer();
                 tapGestureRecognizer.Tapped += async (s, e) =>
                 {
    
        // Maybe u like https://github.com/aritchie/userdialogs to show LOAD modal :)
        // Show Modal
                await getEmployeepage(mainContact.managerID);                   
    
               //   Hide Modal  
                await Navigation.PushAsync(new ManagerDetailsPage(data()));//should execute after the above call completes.
    
    
    
                 };
                 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              
    
    }
    
    
    }
    

Answers

  • RafaelMouraRafaelMoura BRInsider, University, Developer Group Leader ✭✭✭
    Accepted Answer

    @VenkataKrishnaChikkala hey

    Try:

    //code
    
    
                var tapGestureRecognizer = new TapGestureRecognizer();
                 tapGestureRecognizer.Tapped += async (s, e) =>
                 {
    
        // Maybe u like https://github.com/aritchie/userdialogs to show LOAD modal :)
        // Show Modal
                await getEmployeepage(mainContact.managerID);                   
    
               //   Hide Modal  
                await Navigation.PushAsync(new ManagerDetailsPage(data()));//should execute after the above call completes.
    
    
    
                 };
                 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              
    
    }
    
    
    }
    
Sign In or Register to comment.