Handle Back Press event in 2 different pages - c#

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.

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.

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 .

Related

Make Button Ignore ENTER key pressed c#

im building a page using ASP.NET, however, the first element of my page is a Button and there are other elements below it, however, if the client types something and it shows a confirmation box, and he presses ENTER key, it activates the first button at the page.
I tried to change the tab order does not work.
sorry for noob question xD
Have you tried setting UseSubmitBehavior=False on the first button?
Don't handle the click event. Handle the MouseClick event instead. So whatever code is in click, simply move to the MouseClick event

C#.NET mnemonics unexpected behaviour

I have few buttons in my windows application which has mnemonics.Now if i press multiple keys the events of the button clicks gets fired as i have used mnemonics.
But the behaviour is not as expected,because second button event handler is getting executed before the first button event handler has finished its execution,and also i have written my code in such a way that in the event handler of first button i am disabling my second button,still the second button event handler is getting executed.The problem here is due to mnemonics.PLease suggest me a better way to handle mnemonics as soon as possible.
Thanks in advance.
If your logic is tied to your buttons, change that. Let your buttons merely manipulations an object that implements your logic. You can then check in this object whether the requested action is allowed (i.e. whether the previous operation has finished.
Alternatively you can just disable buttons when running and re-enable then when.finished.

about ToolStripMenuItem

I'm having one ContextMenuStrip in that strip at runtime I'm adding one ToolStripMenuItem. And I added this ContextMenuStrip in the XtraGridView's MouseDown() event handler. And at the same time I've added the event handler for the newly inserted ToolStripMenuItem. And I have written one Event handler function for that ToolStripMenuItem. My problem of application is that when user right clicks on the XtraGridView it shows the required menu which I have added at runtime. And when I click on newly added ToolStripMenuItem it executes required event handler function but when I again do the same procedure the event handler function is executed for two times and so on...
Can anyone solve this problem?
Thanks.
You probably are subscribing to the Click event, in XtraGridView's click event. Each time the GridView's click event is raised causes you to subscribe to the click event handler again, so when user actually clicks on the ToolStripMenuItem all the handlers are called.
I suggest moving the subscription code to somewhere else.

Moving button stops click event happening

I have a button, contained in a panel, with a click event, that works fine. However when a users presses another button, I need to move this button into another panel (this is actually a panel with a modalpopupextender), so I this code to do so:
newPanel.Controls.Add(buttonPanel)
It all get's moved and looks fine. However now when the button is clicked it doesn't fire the associated event. I have tried re-adding the event in the page_init, with this code
((Button)this.FindControl("serverModalSave")).Command += new CommandEventHandler(modalSave_Click);
But with no luck. How can I get this button to fire it's click event when moved, and why does it stop working when it's moved?
EDIT:
This Button needs to be added to a panel specified by the user at run time, so there is not a way to determine where the button will go in advance.
I could instead of moving this button, create a new one, but because this button is not created in the page_init I am having issues getting that to fire an event either.
Instead of moving the button, have another button on the other panel set to hidden.
Hide the button you wanted to move and show the hidden one when needed.
Moving the control changes the naming hierarchy and now the button can't be found and the click event can't fire.
This is due to how the page life cycle works. Here is a good (if somewhat dated) article about how view state works - if you understand this, you will understand what went wrong.
If you are creating the button in the new panel, when this button is then clicked do you re-create it in the postback ?
You must re-create all controls on each postback see here

Button click is again fired on reload

When page is reloaded it again goes to last event(e.g. Button click).Is there any way to prevent this?
If you are reloading the page by 'refreshing' (F5), and clicking to accept the resubmission of values, the button click event firing again is by design.
If it's something else, we need much more information to help.
Try to add a Response.Redirect to the current page in the end of your event handler.

Categories