Hide Copy Code
Code
I am building xamarin cross platform portable application.Code
using following steps: 1.Added service reference.Code
2.On button click in login page ,I used to validate user from db,Code
if successful then move to next page else show up message. here is the code.Code
Code
Problem is if I entered incorrect credentials,Code
than alert does show up, but on other hand if entered correct credentials,Code
then show up "Unhandle Exception message show up"Code
I have tried all possible solutions but stuck here for last two days.Code
pre lang="c#">pre>xml version="1.0" encoding="utf-8" ?>Code
ContentPage xmlns="http://xamarin.com/schemas/2014/forms"Code
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="FypXFP.Login">Code
ContentPage.Content>Code
StackLayout>Code
Label Text="UserName" />Code
Entry x:Name="tbuserentry" Placeholder="UserName">/Entry>Code
Label Text="Password">/Label>Code
Entry x:Name="Pwd" IsPassword="True" Placeholder="Password">/Entry>Code
Button x:Name="Save" Clicked="Save_Clicked" Text="Login">/Button>Code
/StackLayout> /ContentPage.Content> /ContentPage>Code
Code
Code
using System;Code
using System.Collections.Generic;Code
using System.Linq;Code
using System.ServiceModel;Code
using System.Text;Code
using System.Threading.Tasks;Code
using Xamarin.Forms;Code
using Xamarin.Forms.Xaml;Code
namespace FypXFP {Code
[XamlCompilation(XamlCompilationOptions.Compile)]Code
public partial class Login : ContentPageCode
{ private FypXFP.ServiceReference1.CMSServiceClient _client;Code
public Login() { InitializeComponent(); }Code
private void Save_Clicked(object sender, EventArgs e)Code
{ var endpoint = new EndpointAddress("http://192.168.43.101/FYP_Admin/webservices/cmsservice.svc");Code
var binding = new BasicHttpBindingCode
{ Name = "basicHttpBinding",Code
MaxBufferSize = 2147483647,Code
MaxReceivedMessageSize = 2147483647 };Code
TimeSpan timeout = new TimeSpan(0, 0, 30);Code
binding.SendTimeout = timeout;Code
binding.OpenTimeout = timeout;Code
Code
binding.ReceiveTimeout = timeout;Code
_client = new FypXFP.ServiceReference1.CMSServiceClient(binding, endpoint);Code
string uname = tbuserentry.Text.Trim();Code
string password = Pwd.Text.Trim();Code
_client.ValidateUserAsync(uname, password);Code
_client.ValidateUserCompleted += _client_ValidateUserCompleted;Code
} public async void Redirect(Boolean Result)Code
{ if (Result == true)Code
{Code
Navigation.InsertPageBefore(new TicketPage(), this);Code
await Navigation.PopAsync(); }Code
elseCode
{Code
await DisplayAlert("Alert", "Something wrong", "Cancel");Code
}Code
}Code
private void _client_ValidateUserCompleted(object sender, ServiceReference1.ValidateUserCompletedEventArgs e)Code
{Code
if (e.Result == true)Code
{Code
Device.BeginInvokeOnMainThread(() => {Code
Redirect(true);Code
});Code
} elseCode
{Code
Device.BeginInvokeOnMainThread(() => {
Redirect(false);Code
});Code
}Code
} } }

Suthahar JegatheesanRank #162 · 14.5K reputationPosted Aug 22, 2017, 2:27 AM EDT
in the App class you can set the MainPage to a Navigation Page and set the root page to your ContentPage:
Then in your first ContentPage call or after your validation
Manikandan MurugesanRank #300 · 8.4K reputationPosted Aug 13, 2017, 4:29 PM EDT
Ravishankar VelladuraiRank #352 · 7.1K reputationPosted Aug 15, 2017, 9:14 AM EDT
Umair HassanRank #386 · 6.5K reputationPosted Sep 10, 2017, 7:53 AM EDT