Interuppted Postbacks

  • Thread starter Thread starter Ben Barter
  • Start date Start date
B

Ben Barter

We have found a fundemental problem with the way that
postbacks are handled. We have a page that has about 60
postback controls that are posted back to the server when
the user clicks a link (LinkButton).

The page takes about 5 seconds to render. A problem occurs
when the user clicks the link, gets the page back to the
browser, then immediately clicks the postback link again.

In this situation the page has not finished rendering, but
gets interuppted and posts back the data to the server.

We find that only some of the postback items in the form
are being returned to the server. Instead of 60 items
coming back, we now have received only (say) 30 items.

The consequence of this, is that the postback controls
whose values were not passed back are now considered to be
blank. When the page renders again, the values of those
controls have been lost!

Someone must have come across this problem before?

How do we stop the user from pressing the postback button
before the page has finished rendering?

We thought of trapping the onSubmit of the form (in
JavaScript), but this only fires for real Submit buttons,
our postback control is a LinkButton. Alternatively, is
there a way to alter the standard __doPostBack function?

Or is there another solution?
 
Ben Barter said:
We have found a fundemental problem with the way that
postbacks are handled. We have a page that has about 60
postback controls that are posted back to the server when
the user clicks a link (LinkButton).

<snip>

We thought of trapping the onSubmit of the form (in
JavaScript), but this only fires for real Submit buttons,
our postback control is a LinkButton. Alternatively, is
there a way to alter the standard __doPostBack function?

This can indeed be a problem; I solved it by extending the __doPostBack
function as you suggested.

Include some JavaScript in your application:

var blnSubmit = false;

// Grab the function of the original __doPostBack function

var __DotNet__doPostBack = __doPostBack;

// Replace the function with your own

__doPostBack = __Extended__doPostBack;

// Declare your own function

function __Extended__doPostBack(eventTarget, eventArgument)
{
if (blnSubmit == false)
{
blnSubmit = true;
__DotNet__doPostBack(eventTarget, eventArgument);
}
}

Code is not tested so it can (knowing me, *will*) contain errors. But you
get I idea.

Steven

- - -
 
Thanks for the code example. This is great for stopping
users pressing a submit button more than once.

However, the problem we have is trying to stop users
pressing a submit button before the page has completed
rendering.

I can use your code to stop the submit before the page
render. Unfortunately, pressing a submit button stops
rendering of the page, and we are left with an incomplete
page.
 
Ben Barter said:
I can use your code to stop the submit before the page
render. Unfortunately, pressing a submit button stops
rendering of the page, and we are left with an incomplete
page.

Ah, sorry, must have read your question too quickly.

A possible solution I see is to disable the submit button initially
(Enabled=false) and enable it again in JavaScript on the client when the
page is fully loaded: <body onLoad="Body_Onload();">. Build this client-side
function in your codebehind so you can you btnSubmit.ClientID to get the
client-side ID of your submit button.

As an alternative, you could use the previous code, but set blnSubmit to
"true" initially and set it to "false" on the onLoad event: <body
onLoad="blnSubmit = false;">. That way pressing the submit button will not
work before the page is fully loaded AND it can only be pressed once.

Steven

- - -
 
N S S said:
There is a client side window_onload Event, that fire when page is
fully loaded on the client

IIRC, this only works on IE without using onLoad="window_onload();"

Steven

- - -
 
Back
Top