0

Hi and thanks for reading in advance... I have a project designed to deliver a client booking system for a kayak company and have created the initial login page, which works for all intent and purposes with respect to validation but when I click the login button [and the details seem to be validated, it doesn't shift over to the next content page [view]. I've attached a video link showing the issue in practice, but I would appreciate some help in discovering what stupid thing I've missed as I've been at it all night and today and think I've gone a bit blind to the obvious!? Navigation Issue Screen Recording

    private void BtnLogin_Clicked(object sender, EventArgs e)
{
    //shifty debug
    btnLogin.Text = "click received...";

    string user = entUsername.Text;
    string pass = entPassword.Text;
    string[] users = new string[result.Members.Length];
    string[] passes = new string[result.Members.Length];
    for (int i = 0; i < result.Members.Length; i++)
    {
        users[i] = result.Members[i].Usr;
        users[i] = result.Members[i].Pass;
    }

    if (user == string.Empty || pass == string.Empty)
    {
        InputError($"User: {user}\nPass: {pass}\n Nothing was entered in one of the text fields");
    }
    else
    {
        switch (user)
        {
            case "gruff":
                case "kieran":
                    case "zara":
                    {
                        NextPage();
                        break;
                    }
            default:
                InputError($"User: {user}\nPass: {pass}\n Not a correct user and/or password");
                break;
        }
    }
}
private void InputError(string v)
{
     Navigation.PushModalAsync(new InfoModal(v));
}
private void NextPage()
{
    btnLogin.Text = "At NextPage Method caledl";
    //so after a number of attempts to show a modal or next page 
    //some success with modal above, but possibly hangs after... i think
    //no success with content page change: the start for tomrorrow :/
    Navigation.PushAsync((new ClientMainPage()));
}

Below is the whole code sheet for better clarity, but it's the code above that's fired and producing my questionable outcome I think :(

public partial class MainPage : ContentPage
{
    //simple admin cover fr viewing xml data
    private const string admin = "123";
    private bool revealState = true;
    private System.Xml.Serialization.XmlSerializer serializer;
    private XmlMemberData result;

    public MainPage()
    {
        InitializeComponent();
        GetMembers();
    }

    private async void GetMembers()
    {
        await using var stream = await FileSystem.OpenAppPackageFileAsync("Members.xml");

        serializer = new System.Xml.Serialization.XmlSerializer(typeof(XmlMemberData));

        result = (XmlMemberData)serializer.Deserialize(stream);

        IEnumerable<Member> members = result?.Members.ToList();
    }

    private void BtnMembersCheck_Clicked(object sender, EventArgs e)
    {    
        if(revealState)
        {
            string adminKey = entAdminKey.Text;

            if (adminKey != admin)
            {
                adminKey = "";
                entAdminKey.Text = string.Empty;

                //pop up a modal warning? - UX
                return;
            }

            var members = result?.Members.ToList();

            switch (members?.Count)
            {
                case 0:
                    StatusLabel.Text = "None Found, Are you sure you created any users?";
                    break;
                case > 0:
                    StatusLabel.Text = $"{members.Count} Members Loaded!";
                    BooksListControl.ItemsSource = members;
                    btnMembersCheck.Text = "ClearData";
                    revealState = !revealState;
                    break;
                default:
                    StatusLabel.Text = "Something went wrong";
                    break;
            }
        }
        else
        {            
            StatusLabel.Text = "To View Again Re-Enter Admin Key";
            entAdminKey.Text = string.Empty;
            btnMembersCheck.Text = "Reload Admin Keys";
            BooksListControl.ItemsSource = null;
            revealState = !revealState;
            return;
        }       
    }

    private void BtnLogin_Clicked(object sender, EventArgs e)
    {
        //shifty debug
        btnLogin.Text = "click received...";

        string user = entUsername.Text;
        string pass = entPassword.Text;
        string[] users = new string[result.Members.Length];
        string[] passes = new string[result.Members.Length];
        for (int i = 0; i < result.Members.Length; i++)
        {
            users[i] = result.Members[i].Usr;
            users[i] = result.Members[i].Pass;
        }

        if (user == string.Empty || pass == string.Empty)
        {
            InputError($"User: {user}\nPass: {pass}\n Nothing was entered in one of the text fields");
        }
        else
        {
            switch (user)
            {
                case "gruff":
                    case "kieran":
                        case "zara":
                        {
                            NextPage();
                            break;
                        }
                default:
                    InputError($"User: {user}\nPass: {pass}\n Not a correct user and/or password");
                    break;
            }
        }
    }
    private void InputError(string v)
    {
         Navigation.PushModalAsync(new InfoModal(v));
    }
    private void NextPage()
    {
        btnLogin.Text = "At NextPage Method caledl";
        //so after a number of attempts to show a modal or next page 
        //some success with modal above, but possibly hangs after... i think
        //no success with content page change: the start for tomrorrow :/
        Navigation.PushAsync((new ClientMainPage()));
    }
}

So to reiterate, the issue is around navigating between one page to another on a button click, that appears to be firing and the modal alternative for validation is working as expected, but when the correct details are found, it doesn't fire the new page as expected :( I know its something I'm missing that obvs, but I am fairly new to this environment so it would be great to know what it is that I'm stumbling on so I can put it into the silly gotchas box. Thanks so much again to anyone who read this far and can help. (Below is a copy of the project in case what I've said is just not as easy to decipher without a proper look)

SKT Project @ GoogleDrive

gruffy321
  • 175
  • 2
  • 13
  • 2
    does it reach the `PushAsync()` line? Do you get any errors or exceptions? Is `MainPage` contained in a `NavigationPage`? – Jason May 16 '22 at 16:25
  • 1
    Could be something wrong with ClientMainPage. In App.xaml.cs, if you change code to `MainPage = new ClientMainPage();` does the page show? – ToolmakerSteve May 16 '22 at 16:40
  • so, no I dont get errors, and it reaches the async method I'm pretty sure [as can be seen in screen recording hopefully when the button text changes accordingly once inside the method that fires the async page] no exceptions either when the project runs, just non-functionality of the call to the new Navigation page async function invoked after the button press has happened Thank you :) – gruffy321 May 16 '22 at 16:48

1 Answers1

0

So it looks like I was a complete idiot and did NOT change the teh App.xaml.cs to invoke a navigation page on app entry for MainPage()

I'm such a clutz, but guess its due to not taking regular breaks and getting lost in it all doh. I have to thank @ToolMakerSteve for his nod to APp.xaml, as when I got there i noticed it wasnt in the Navigation Page setup

was...

MainPage = new MainPage();

now...

MainPage = new NavigationPage( new MainPage());

THIS SOLVED HAS THIS ISSUE [and somewhat my sanity, thank you for being there as a soundboard Stackoverflow and contributors] Of course it revealed my validation sucks as any password and any user name combo can get to next view now lol so now need to correctly control that :)

gruffy321
  • 175
  • 2
  • 13