398,048 Members | 1,233 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 398,048 IT Pros & Developers. It's quick & easy.

Deactivate Refresh and F5 event

subbusuresh
P: 5
hi

Any one can help me.

how to deactivate the Refresh / F5 Event in asp.net

Please
Sep 19 '07 #1
Share this Question
Share on Google+
3 Replies


aliasruel
P: 73
Hi,

Open the inline code of your webform and then you may paste this code below. this code will prevent the F5/Refresh event.
================================================== ===
<script language="javascript">
function disableKey(event) {
if (!event) event = window.event;
if (!event) return;
var keyCode = event.keyCode ? event.keyCode : event.charCode;
//window.status = keyCode;
//alert(keyCode);

// keyCode for F% on Opera is 57349 ?!

if (keyCode == 116) {
window.status = "F5 key detected! Attempting to disabling default response.";
window.setTimeout("window.status='';", 2000);

// Standard DOM (Mozilla):
if (event.preventDefault) event.preventDefault();

//IE (exclude Opera with !event.preventDefault):
if (document.all && window.event && !event.preventDefault) {
event.cancelBubble = true;
event.returnValue = false;
event.keyCode = 0;
}
return false;
}
}

function setEventListener(eventListener) {
if (document.addEventListener) document.addEventListener('keypress', eventListener, true);
else if (document.attachEvent) document.attachEvent('onkeydown', eventListener);
else document.onkeydown = eventListener;

if (!document.getElementById) return;
var el = document.getElementById("Msg");
if (el) el.innerHTML = "Event handler added.";
}

function unsetEventListener(eventListener) {
if (document.removeEventListener) document.removeEventListener('keypress', eventListener, true);
else if (document.detachEvent) document.detachEvent('onkeydown', eventListener);
else document.onkeydown = null;

if (!document.getElementById) return;
var el = document.getElementById("Msg");
if (el) el.innerHTML = "Event handler removed.";
}
</script>


fortunately it l works with Netscape 7.1 and IE6 and Mozilla 1.6
:)

Best Regards,
Ruel Sucgang



================================================== ====
hi

Any one can help me.

how to deactivate the Refresh / F5 Event in asp.net

Please
Sep 19 '07 #2

subbusuresh
P: 5
hi,

its very useful to me

Thank You...
Sep 19 '07 #3

Plater
Expert 5K+
P: 7,872
You should be using the isPostback boolean to deterimine if someone has clicked a button or pushed refresh
Sep 19 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.