1

I have two different pages in my Windows Phone 8.1 Store application, say Page_1 and Page_2. I have two different event handlers for the Phone's Back Press event on the two pages. Strangely when I'm on Page_2 and I press the Back button, the event handler on Page_1 is getting invoked. Can someone help me out with this issue? I want the event handler of the page in which I am to be invoked when I press the back button from that page.

Romasz
  • 29,662
  • 13
  • 79
  • 154
Abhishek Das
  • 82
  • 4
  • 11
  • possible duplicate of [Windows Phone 8.1 override back button on a certain page](http://stackoverflow.com/questions/26992703/windows-phone-8-1-override-back-button-on-a-certain-page) – Romasz Mar 25 '15 at 10:44
  • Please add some code, what you have tried, and where you are stuck. – Praxis Ashelin Mar 25 '15 at 14:20
  • I have two pages: 1.Login Page and 2.Page having a WebView control. In the first page the event handler to the back press event is for exiting the app. And in the second page, it is for taking the WebView to its previously rendered html page until it reaches the starting point, on which it would be navigated to the first page. The issue now is, when I'm in my second page and I press the Back button, the event handler to the first page is getting called. I'm using Frame.Navigate to navigate between my pages. – Abhishek Das Mar 25 '15 at 19:49

2 Answers2

0

If you navigate from Page_1 you should remove the event handler which you added. And on Page_2 simply add the handler for that page.

WPMed
  • 1,414
  • 1
  • 13
  • 25
  • I did not get you. The back press event for both of my pages are significant and has different operational requirements. I cannot remove either of them. – Abhishek Das Mar 25 '15 at 19:52
  • You should add the handlers in OnNavigatedTo, and remove them in OnNavigatedFrom. On Page_2 you do not need Page_1 back button handler, so you can remove it, and add it again if you navigate to it. You get it? – WPMed Mar 25 '15 at 20:38
0

you have add back pressed event in page2 onNavigateTo method add conditions you want to execute on that page and remove back pressed event in onNavigateFrom .

Asieh hojatoleslami
  • 3,240
  • 7
  • 31
  • 45
Kushal Maniyar
  • 846
  • 1
  • 8
  • 26