I’ve got a simple question. If I’m using a Response.Redirect(), will that kill all page functionality assuming the user cancels the redirect?
For example, pretend I have a page with a button that, when pressed, pops up a message that says “hi”. Then, at some point in the code, the user encounters a Response.Redirect(). Before the page is cleared on the browser, they hit STOP in their browser. Then, they click the button. Will it still say “hi”, or will the page be non-functional?
EDIT FOR MORE INFORMATION:
Maybe I am just not understanding the answers, but I still don’t have an answer to my question.
Let me rephrase to be more precise.
I have two buttons that both execute a C# function when they are clicked. One of them executes a Response.Redirect() to a different page. The other prints out “Hi” in a message box. The user presses button 1. The response.redirect starts processing, but before the user is redirected they decided that they made a mistake and they hit the STOP button in their browser. The user is still looking at the same web page. They click on button #2. My question is, does the message “Hi” pop up? Does the C# function still work? Or would the code behind be inaccessible after the attempted redirect?
Solution
Users on a slow network connection do see the initial page for a little longer.
If all you want to do is prevent them from pressing those buttons by mistake, you can create a
<div>to cover your entire screen area and grey it out with a semi-transparent image. Users will not be able to click buttons unless they refresh the page.You can get this effect easily by showing a jQuery modal dialog on form submit, with a message to the user that the data is being saved.
This solution will only prevent the accidental click. If you want to prevent malicious repeated requests, in addition to the modal dialog you should track your application state on the server and indicate that a save has already taken place. A simple session variable should suffice to indicate this.
Technical explaination
The http protocol used by the web server is stateless. Every time you send a request to the server, it builds your Page object to service this request and returns a reply. It will not remember what you send it last time. If you need that, you have to do it yourself.
When you click the “hi” button, in your c# code you set the message. In reply to this request the server replies with a success status message
HTTP/1.1 200 OKas the first line of the response. This tells the browser that everything is ok, and it will process the response based on theContent-Typeheader returned.When you click the button to redirect to another page. Your browser sends a request to the first page. There when you execute a
Response.Redirectyour server send back a redirect message to the browser.This tells the browser that it has to go to this new location to get a response. The browser now makes a new request to the url mentioned by the location header and gets the response.
The user may abort the request at any of these stages. Since http is stateless, you can resubmit and of the two requests or click on another button and make a new request. The server will dutifully send it to asp.net like nothing ever happened and you will get a response.