N
noneya22
I'm using asp.net 2.0. I have a page that has a save button and a
cancel button along with a text field. All controls are asp.net
server controls. I have JavaScript that prompts the user if he has
maninpulated data in the text field and then tries to leave the page.
The purpose is to prevent the user from accidentally losing his
changes. This JavaScript code that accomplishes this is based upon
the code found at http://aspnet.4guysfromrolla.com/articles/101304-1.aspx.
Basically it makes use of the window.onbeforeunload event to prevent
navigation from the current page.
The cancel button has the PostbackUrl property set. The reason for
this is to navigate to the page the user was at before the current
page thus cancelling the operation. I understand that there are other
ways of achieving the scenario I have described here (i.e. hyperlink,
postback with a server redirect, etc.). I'm trying to keep this
example simple. Also, the save button does not have the PostbackUrl
property set as it is intended to cause a postback to the same page
and process the data.
So, here is the problem scenario. If the user manipulate's the text
in the text field and clicks the cancel button, he receives a prompt
that allows him to stop the current operation and stay on the current
page. What is happening is once this occurs, every other input
control on the form now will post to the URL set on the cancel
button's PostbackUrl property. Say the user now clicks the Save
button, they will not post back to the same page, and thus save the
data, they will post to the page specified by the cancel button's
PostbackUrl property.
I believe this has something to do with the code executed by
WebForm_DoPostBackWithOptions, but I am not sure. It seems as if the
form's target gets reset to the postback url, maybe by this code, and
then you're stuck. Any suggestions on why this is occurring and how
to prevent it would be much appreciated.
Thanks!
cancel button along with a text field. All controls are asp.net
server controls. I have JavaScript that prompts the user if he has
maninpulated data in the text field and then tries to leave the page.
The purpose is to prevent the user from accidentally losing his
changes. This JavaScript code that accomplishes this is based upon
the code found at http://aspnet.4guysfromrolla.com/articles/101304-1.aspx.
Basically it makes use of the window.onbeforeunload event to prevent
navigation from the current page.
The cancel button has the PostbackUrl property set. The reason for
this is to navigate to the page the user was at before the current
page thus cancelling the operation. I understand that there are other
ways of achieving the scenario I have described here (i.e. hyperlink,
postback with a server redirect, etc.). I'm trying to keep this
example simple. Also, the save button does not have the PostbackUrl
property set as it is intended to cause a postback to the same page
and process the data.
So, here is the problem scenario. If the user manipulate's the text
in the text field and clicks the cancel button, he receives a prompt
that allows him to stop the current operation and stay on the current
page. What is happening is once this occurs, every other input
control on the form now will post to the URL set on the cancel
button's PostbackUrl property. Say the user now clicks the Save
button, they will not post back to the same page, and thus save the
data, they will post to the page specified by the cancel button's
PostbackUrl property.
I believe this has something to do with the code executed by
WebForm_DoPostBackWithOptions, but I am not sure. It seems as if the
form's target gets reset to the postback url, maybe by this code, and
then you're stuck. Any suggestions on why this is occurring and how
to prevent it would be much appreciated.
Thanks!