After user views and possibly interacts with a page using client script, a refresh or "back button" click causes the page to be re-rendered as it was initially. Is there a way to detect and reject such a refresh or back button action?
Interesting possibility, but I don't think I can use Update Panel to trigger a partial update when user clicks the back or refresh buttons. I think I can only control what happens when user clicks one of my controls (linkbutton, etc).
After user views and possibly interacts with a page using client script, a refresh or "back button" click causes the page to be re-rendered as it was initially.
Hello,
That's not true. When you press the back button, the browser takes the page from cache. It does not send a request to the server unless you have explicitly set no cache for the page. But when you press refresh, it sends a request to the server and gets new
data. So there is a big difference between browser back button and refresh button
uick383937
Is there a way to detect and reject such a refresh or back button action?
What you can do is, detect the keystrokes such as F5 and R then disable those keys. But I do not recommend this. Why do you need to disable those? If user cannot refreh a particualr page, he simply reload the same page again by entering
the URL. So it's actually pointless to disable the refresh ability. It's never been a good user experience too. If user refresh the page, that means either the page does not load correctly or s/he needs new data to be displayed. Do not disable those feautures.
Thanks for your information. I'm glad to learn the difference between Refresh and Back.
Here's my problem:
I have a webpage that presents a Sudoku puzzle to the user and, via JavaScript, provides lots of tools to help solve it. It also keeps track of the time the puzzle is open and of various user actions like "check an answer" or "peek". I compute a score
based on these items, and would like to be able to use this in "contest mode", where best user score wins. However, it appears that a user can play for an extended period, discovering the puzzle solution, then reload the page and enter fast and accurate answers,
thereby posting a good score.
However, it appears that a user can play for an extended period, discovering the puzzle solution, then reload the page and enter fast and accurate answers, thereby posting a good score.
Is there a way to circumvent this?
Hi,
We can use cookies for that. When the user already finished playing, you can set a cookie value in user's web browser. Check that cookie value at the page load so you can know if it's a first time user or a user who has already played the game. By setting
the cookie expiration, you can allow users to play the game again, once s/he forgets the puzzle solution :)
If you would like user to play ONLY a one time, then it's better to keep a flag value in the database and check that value when user tries to play the game.
I am using a cookie to keep track of the puzzle state in the browser. By design, I want user to be able to work the puzzle for extended period without posting back to host (thus can work without an internet connection). User can close a puzzle, then resume
it later without posting back to the host since all necessary info is in the cookie. But this means that user can refresh and essentially "start over" with the puzzle in its initial state. But now, of course, the user knows all the answers!
I'm thinking that in "contest mode" I will need to postback as user works the puzzle and keep status on the host.
uick383937
Member
81 Points
117 Posts
How to reject a refresh?
May 02, 2012 06:52 PM|LINK
After user views and possibly interacts with a page using client script, a refresh or "back button" click causes the page to be re-rendered as it was initially. Is there a way to detect and reject such a refresh or back button action?
Thanks.
Gaspard
Contributor
2066 Points
416 Posts
Re: How to reject a refresh?
May 02, 2012 06:58 PM|LINK
Maybe you can use updatepanel because
"UpdatePanel controls work by specifying regions of a page that can be updated without refreshing the whole page".
http://www.asp.net/ajax/documentation/live/overview/UpdatePanelOverview.aspx
Regards
uick383937
Member
81 Points
117 Posts
Re: How to reject a refresh?
May 02, 2012 08:53 PM|LINK
Interesting possibility, but I don't think I can use Update Panel to trigger a partial update when user clicks the back or refresh buttons. I think I can only control what happens when user clicks one of my controls (linkbutton, etc).
rossisdead2
Participant
1313 Points
300 Posts
Re: How to reject a refresh?
May 02, 2012 11:06 PM|LINK
You can use javascript to prompt the user during the window.onbeforeunload event, but ultimately you can't prevent them from doing it.
Ruchira
All-Star
43050 Points
7037 Posts
MVP
Re: How to reject a refresh?
May 03, 2012 02:49 PM|LINK
Hello,
That's not true. When you press the back button, the browser takes the page from cache. It does not send a request to the server unless you have explicitly set no cache for the page. But when you press refresh, it sends a request to the server and gets new data. So there is a big difference between browser back button and refresh button
What you can do is, detect the keystrokes such as F5 and R then disable those keys. But I do not recommend this. Why do you need to disable those? If user cannot refreh a particualr page, he simply reload the same page again by entering the URL. So it's actually pointless to disable the refresh ability. It's never been a good user experience too. If user refresh the page, that means either the page does not load correctly or s/he needs new data to be displayed. Do not disable those feautures.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.Gaspard
Contributor
2066 Points
416 Posts
Re: How to reject a refresh?
May 03, 2012 03:20 PM|LINK
Thank you Ruchira for your explanations
Regards
uick383937
Member
81 Points
117 Posts
Re: How to reject a refresh?
May 03, 2012 05:15 PM|LINK
Thanks for your information. I'm glad to learn the difference between Refresh and Back.
Here's my problem:
I have a webpage that presents a Sudoku puzzle to the user and, via JavaScript, provides lots of tools to help solve it. It also keeps track of the time the puzzle is open and of various user actions like "check an answer" or "peek". I compute a score based on these items, and would like to be able to use this in "contest mode", where best user score wins. However, it appears that a user can play for an extended period, discovering the puzzle solution, then reload the page and enter fast and accurate answers, thereby posting a good score.
Is there a way to circumvent this?
Thanks again.
sriramabi
Contributor
4351 Points
1277 Posts
Re: How to reject a refresh?
May 03, 2012 05:17 PM|LINK
Alternatively you can use jquery with a C# handler to upload a file. It will not cause any post back..
and
I can give you some links which will give you idea about avoiding page refresh please go through it:
Prevent Page Refresh in C#[^]
Detecting Page Refresh[^]
How to prevent page refresh in asp.net[^]
This question was already ask'd on this forum; see if you get some help from it:
how to avoid page refreshing while uploading file[^]
Ruchira
All-Star
43050 Points
7037 Posts
MVP
Re: How to reject a refresh?
May 03, 2012 05:53 PM|LINK
Hi,
We can use cookies for that. When the user already finished playing, you can set a cookie value in user's web browser. Check that cookie value at the page load so you can know if it's a first time user or a user who has already played the game. By setting the cookie expiration, you can allow users to play the game again, once s/he forgets the puzzle solution :)
If you would like user to play ONLY a one time, then it's better to keep a flag value in the database and check that value when user tries to play the game.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.uick383937
Member
81 Points
117 Posts
Re: How to reject a refresh?
May 03, 2012 07:28 PM|LINK
I am using a cookie to keep track of the puzzle state in the browser. By design, I want user to be able to work the puzzle for extended period without posting back to host (thus can work without an internet connection). User can close a puzzle, then resume it later without posting back to the host since all necessary info is in the cookie. But this means that user can refresh and essentially "start over" with the puzzle in its initial state. But now, of course, the user knows all the answers!
I'm thinking that in "contest mode" I will need to postback as user works the puzzle and keep status on the host.
Thanks for your suggestions.