views:

964

answers:

6

I was hoping if anyone can answer a fundamental question that I have regarding refreshing of a web page.

I have a dotnet webform where a user fills in some details and clicks submit. The code behind of the webpage has about 20 functions to perform.

Now assuming, when the user clicks the submit button the web page is executing the 5th function and meanwhile the user refreshes his browser;

What will happen to the already processing page? Will the page be terminated immediately? or will it be allowed to run till it executes the 20th function? or will the page running be destroyed and a new page created and sent to client?

Thanks for your answers.

A: 

Simply, the page the user is seeing is lost unless in session, they can not pick it up again. But the server does not know that the user has disconnected so the application will continue to run, unless there is a session / timeout on the application, even then it would be odd if the session did not complete.

Hope this helps.

RE

Reallyethical
A: 

The code execution will continue to the end.

Dani
hmmm... care to provide a reference to this claim?
jldupont
@Dani - not true. at least for PHP i know.
thephpdeveloper
for asp.net it does, at least when I accidentally hit refresh on the page while the server was stuck on a long operation, I see that it completes all the code and only then reloads the page.
Dani
Guys - this has nothing to do with the server side **unless** the client side sends XHR requests to the server **before** completing the page. Even then, if you hit reload, a good behaving browser **will** reload.
jldupont
Think of the implications - if it wasn't like this - and you're buying something online, you hit submit - the request reached the server, and being processed, while they clear your credit card against the bank you hit refresh - or home-page... will the transaction abort ?(money already gone, and the server is "working" on generating you recipt...)
Dani
There is no question - if the browser reloads.it will reloads, but the functions on the server side that run (from the submit on the older page) will run until the end.
Dani
A: 

I believe a web page (on the client side of course) is executed in a single thread. If your "onsubmit" calls a trail of functions, that's up to you but at some point you will (maybe) want to submit() the form.

In other words (in your specific case), all the function trail will continue until the form is sent.

On the other hand, if you press the "reload" button, the execution is terminated.

jldupont
A: 

When a page is refreshed on the browser, the browser calls on the server for a fresh copy of the page and its components (CSS, JS, and so on... if not cached).

If the page was a POST call, the browser will POST the data again.

Page has completed loaded:

When loaded completely, the execution on the server side should be completed (unless you execute additional processes, or run background code which will not send anymore data to the client).

Page is loading halfway through:

The connection for the current page will be immediately disconnected - if the page is still loading. It depends on the server whether for the page to continue running or terminate. For example in PHP we can ignore_user_abort() to keep the script running even if the page was terminated halfway through loading.

If your server is ASP, and you click on an ASP button, the action (method) of the button will be done completely on server side even if the user refreshes halfway through. That is how ASP.NET framework is done.

thephpdeveloper
Once a page is sent to the client browser, the server has nothing to do with **until** the client wishes to do something else.
jldupont
Of course the server can hold-up the client side by delaying sending the end of the data stream... but that's another story.
jldupont
@jldupont - while the page is loading (the content of the page - not external components), the server still has connection with the client.
thephpdeveloper
@Mauris: yes the server is still connected to the client **whilst** the page is loading... I haven't said otherwise.
jldupont
In this question - the user pushed submit button on a web form. server side code is running. the user pushes refresh on the browser - the server side code (onBunttonClick()) will run through this function until the end.
Dani
A: 

all the funcs will be executed, even you have refresh, you can do a test. but in .net it provide a function to check if client is still connected with server (for your first submit, mean the server can check if client is waiting for the response at anytime after you submit)

Weixiao.Fan
+7  A: 

Once a request is made to the server from the browser the page is processed. Even if the user cancels or stops the request, the server continues to process the request. If the user reloads/refreshes the page, it's another request that will be executed in parallel with the first request.

Even in the case of PHP, the server isn't actively checking if the user has aborted the connection. The server only knows it's been aborted when it attempts to return the results of the request.

The internet is a disconnected environment. The server doesn't know anything about the browser. The only thing the server knows is a request has been made and it must fill the request.

Chuck Conway