Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

The code execution will continue to the end.

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.

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top