Form events

G

Guest

Hi,

I have an ASP.net application that has some javascript written for the
onbeforeunload event which asks the user if they want to save changes before
they leave. However, there is a problem with this because if I click the
Save Changes button it asks me the same question as in the onbeforeunload
event because when the button is clicked it does a postback which causes that
event to fire.

Is there a way that I can get around that so that question doesnt' come up
when I click the save button?

Also is there a way that I can Monitor controls so that the question in the
onbeforeunload event fires only when one of those controls has changed
 
V

Victor Garcia Aprea [MVP]

Hi,

Use an 'isDirty' flag or such. Writing Javascript code attach to the
onchange events of the different elements you want to monitor for changes
and set this flag to true on any changes. A function attached to the onclick
of your Save button should also set this flag to false. Then the function
used to display the alert message will do so only in cases isDirty is true.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Read my weblog:
Followers of the IHttpHandler
http://clariusconsulting.net/vga
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top