I have an online exam system in which after the test, the result is displayed in a new asp.net page. If he clicks on the 'back' button on the browser, he gets back to the page which displays the test again.

What I want to do is disable the user from going back.(Show some message like 'Page has expired' )

Hope you got what I'm trying to say. Is there any way in which this can be done?

Well, I googled a bit (I rely more on daniweb than google these days) and what I found was this cannot be done.

However, a work around this is clearing the cache using a javascript. Javascript might be disabled on your browser, but then I guess there is no other way.

Discussion here: http://forums.asp.net/t/989339.aspx

If anybody has a more elegant solution, I'm all ears.

Well, why don't you try using pop up windows. I mean, sure you will have to deal with the PopUp blockers, but that's another issue and still have to deal with the javaScript problem. At least you get to choose if you want the scroll bars, the navigation bar, the status bar, the width and lenght etc, etc.

My recomendation is IMHO would be: build a profile of the users that will be using your app. Their probable browsers, their OS, their hardware. Then juggle with what you can provide and what they can receive.

I forgot. Check this out. http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911

use this java script in your .aspx page: <script type="text/javascript">history.go(1)</script>

instead of disabling the back button, give each test an id and keep the id in a session variable, on each page load event handler of the test page check if the test id matches the one the user has taken, if that is true response.redirect the user to another page or just alert a message indicating that test has been taken by that user. this is the more prevalent way as far as i have seen on the testing sites.

@Serkan

What about the case in which the test is being taken by a user and then he clicks the back button? How can this situation be handled?

ok then the best way is to seperate the test and the rest of the content on your pages. cisco forexample does this way. when you start the test it opens a new window with all of the explorer tools disabled including resizing. that way there is not even any back button. in this case if you are going to say what if they right click on the page and select the back from the context menu, i would say you can block the context menu with javascript with one lines of code. you can also easily communicate with the opened window and the opener window. what do you think about my second idea? if you dont like this second one i would add some to the first one. if the user clicks the back button while having the test you can not just do anything, but if you create a start button to start the test then you can set the test id before submitting the test. So, even if they havent yet finished the test, you can control the flow of the user via the start button which is a requirement to start the test. also even if they quit before submitting the test, you can keep the given answers via asyncronous postbacks for each answers selected by the user. so your database will have a field with boolean type indicating whether the test has been submited or quit before submission. then user can be able to continue to the test. i know i talked so much but these are just to give you an opion about what could be done about testing. i think opening a second window will be the easiest.

commented: I like the way you think! +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.