Form events

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
Back
Top