When user click on btnOffline on Main page, it will redirect them to second page. I will record the time stamp when user click on button done (button_clicked event) on second Page. The error I am facing right now is when it navigates back to main page after button_clicked event, I click on btnOffline and btnDone again, the timestamp for lblEndDT changes. I only want to get the first click from second page but it still changes
Main Page
public partial class MainPage : ContentPage
{
public string mainpagevalue;
int offlinecount = 0;
int onlinecount = 0;
public MainPage()
{
InitializeComponent();
}
private void btnOffline_Clicked(object sender, EventArgs e)
{
offlinecount++;
txtOfflineStatus.Text = "IN PROGRESS";
Navigation.PushAsync(new SecondPage(this, lblEndDT, txtOfflineStatus, btnOnline, btnMH));
if (offlinecount == 1)
{
string currentDT = DateTime.Now.ToString();
lblStartDT.Text = currentDT;
}
}
Second Page
public partial class SecondPage : ContentPage
{
Label MainPagelblEndDT;
MainPage mainPage;
ImageButton myImageBtn;
int btndonecount = 0;
public SecondPage()
{
InitializeComponent();
}
public SecondPage(MainPage mainP,Label lblEndDT)
{
InitializeComponent();
//Get the lblEndDT reference here
MainPagelblEndDT = lblEndDT;
//Get the MainPage reference here
mainPage = mainP;
}
public SecondPage(MainPage mainP, Label lblEndDT, ImageButton imageBtn)
{
InitializeComponent();
//Get the lblEndDT reference here
MainPagelblEndDT = lblEndDT;
//Get the MainPage reference here
mainPage = mainP;
//Get the ImageButton reference here
myImageBtn = imageBtn;
}
private void Button_Clicked(object sender, EventArgs e)
{
btndonecount++;
if(btndonecount == 1)
{
string edt = DateTime.Now.ToString();
MainPagelblEndDT = edt;
mainPage.mainpagevalue = MainPagelblEndDT.Text;
}
Navigation.PopAsync();
}
}