Tuesday, October 4, 2011

Form resubmit on Refresh

I had issue with resubmitting the form  when user refresh the form. i had to disable this accidental behavior in the MVC3. Yes of cause we can redirect to another action to prevent this behavior. but in my case i do not want to do that. there fore i used following JavaScript to disable browser refresh and back button.

<script>
window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler() {
switch (event.keyCode) {

case 116: // 'F5'
event.returnValue = false;
event.keyCode = 0;
window.status = "F5 disabled";
break;
}
}
</script>
Post a Comment