Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1837
  • Last Modified:

how to disable refresh button for browser in asp.net

Hi experts,

I want to block refresh button for browser .
i am using following javascript ,it works for me ,but it is disabling only F5. Please help

if (document.all){
document.onkeydown = function (){
var key_f5 = 116; // 116 = F5

if (key_f5==event.keyCode){
event.keyCode = 27;

return false;
}
}
}
 
0
gpinfotech
Asked:
gpinfotech
2 Solutions
 
Pratima PharandeCommented:
refer
http://forums.asp.net/p/1279327/2455531.aspx 
private bool _refreshState;
 private bool _isRefresh;

 protected override void LoadViewState(object savedState)
 {
     object[] AllStates = savedState;
     base.LoadViewState(AllStates(0));
     _refreshState = bool.Parse(AllStates(1));
     _isRefresh = _refreshState == Session("__ISREFRESH");
 }

 protected override object SaveViewState()
 {
     Session("__ISREFRESH") = _refreshState;
     object[] AllStates = new object[3];
     AllStates(0) = base.SaveViewState;
     AllStates(1) = !(_refreshState);
     return AllStates;
 }

Open in new window

0
 
robastaCommented:
The  Post-Redirect-Get pattern solves some of the problems related to page refreshing, mainly, reposting data. see here for details: http://en.wikipedia.org/wiki/Post/Redirect/Get and here for sampe: http://www.eworldui.net/blog/post/2008/05/08/ASPNET-MVC-Using-Post2c-Redirect2c-Get-Pattern.aspx

This will not Block the refresh, but it ensures that the user does not post data repeatedly. (Im not sure why you want to block refresh, Im assuming you want to avoid reposting :-) )
0
 
Rose BabuSenior Team ManagerCommented:
Hi,

using javascript you can disable the refresh button.

try the below script in youe page.


<Script language="javascript">
function disableRefresh(evt)
{

	var evt = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if(event.keyCode==116)
	{
		evt.keyCode=0;
		return false
	}
}

document.onkeydown=disableRefresh;

</script>

Open in new window

Hope this may help you.

Happy Programming.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Alpesh PatelAssistant ConsultantCommented:
Please write JS to block the key F5 in keypress or keydown event.
Also hide the REfresh button using javascript.
0
 
gpinfotechAuthor Commented:
Thanks alot
0
 
Amandeep Singh BhullarCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now