I was wondering if anyone knows a way to prevent page redirection? I would like to capture an event when the page leaves, and then run some code. If the code behind meets certain criteria, enable redirection, otherwise cancel it. I know that some of them can be accomplished using Javacript, but the problem I came across actually stops the redirect. Here is what I have:
JavaScript:
<script type="text/javascript">
window.onbeforeunload = confirmExit;
function clickButton(getId) {
var getBtn = document.getElementById(getId)
getBtn.click()
}
function confirmExit(e) {
var btnId = document.getElementById("<%=btnConfirmExit.ClientId %>").id
clickButton(btnId)
}
</script>
Code behind:
Protected Sub btnConfirmExit_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConfirmExit.Click
'if something, cancel request
'else
' let it go
end Sub
If you tried to use:
Page.Response.End()
But it does nothing. Does anyone have any ideas?
thank
jason source
share