How to avoid running a code every time a page is viewed?

JassimRahmaJassimRahma USMember ✭✭✭✭

Hi,

In below code, I am populating list of customers when the page loaded first time:

protected override void OnAppearing()
{
    base.OnAppearing();

    GetCustomersList();
}

but my issue that every time I click on a customer to view its details on CustomerDetailsPage and the press back button it will again fire the GetCustomersList because that's the nature of OnAppearing

How to avoid that and make sure it's just fired on first time?

Any solution please?

Thanks,
Jassim

Best Answer

Answers

  • JSamanoJSamano Member ✭✭

    @JoeManke said:
    private bool _firstAppearance = true;

    protected override void OnAppearing()
    {
        base.OnAppearing();
        
        if(_firstAppearance)
        {
            _firstAppearance = false;
            GetCustomersList();
        }
    }
    

    Thank you @JoeManke

    I just fix my problem with this!

Sign In or Register to comment.