This is impossible right??
This is a very simplified description of my form so don't worry if it
sounds like I could do it a different way, it's just because I have
simplified it. I have two controls. In control 1 you can update a text
value, the onblur event of this control will submit the form and
update the value on the server. When the onclick event of control 2 is
fired the form is submitted and on return the value in control 1 is
populated ready for editting.
You might be able to see the problem. If the onblur of control 1 is
fired because the user is clicking on control 2 then the event
handling code wants to submit the form twice. What happens is that the
onblur event of control 1 is lost because the onclick event of control
2 overtakes it. So if you make a change to control 1 and expect it to
be updated when the focus is lost when you click on control 2 then
you're in for a surprise.
I think that this is a pretty standard problem in a client-server
application like this. Only one event that goes back to the server can
run at a time. Any solutions to get around this are messy and
unintuitive when looking back at the code.
To resolve this issue I simply check in the onclick event of control 2
if a flag has been set by the onblur event of control 1. If it has
then then I show a warning to the user that they will have to click
again (not in an alert() box, which makes matters worse!), and I don't
submit the form because the onblur submit() is running.
Part of the problem is that when you submit a form the client
environment still seems to be running for a sub-second, so events can
get called when they aren't wanted.
I suppose the point of this message is, has anybody else faced this
problem and did they hit a brick wall like I have?
Thanks.