English 中文(简体)
ASP.Net s auto-postback. What happens when its too slow?
原标题:

I am making a web application. I have gotten a weird error with update panels.

Ok, so say you have two update panels and each update panel has a textbox in it. Both of these textboxes are auto-postback and the update panels update conditionally.

Well, from the behavior I m observing it seems like if the server isn t faster than the user at processing a request then it sorta gets ignored on the client side. Like say you type something in 1 of these text boxes and then quickly tab to the next one and type something and tab out. This should cause 2 post backs.

Well, what if 1 post back is being processed at the server and another one happens? Does that post back get dropped at the server side or client side?

The main problem I m observing with this situation is that when a post back occurs the 1st time, there is a Update() for an update panel. Well, when the 2nd post back occurs interrupting the first, it also does an Update on an update panel(a different one). What the user sees is if they tab through it very quickly(or the server is under high load or whatever) then the 2nd update panel gets updated but not the first.

tl;dr: When a post back interrupts another post back, any update panels that were suppose to be updated in the first post back are not updated(though the second postback ones are)

How can I work around this problem or solve it? I can not update all of the update panels on the screen because then the control that the user is currently on loses focus along with a whole lot of other problems.

最佳回答

UpdatePanels intercept the postback and make a request back to the server using the XMLHTTPRequest object (i.e. they use AJAX).

The second XMLHTTPRequest will cancel the first one if it is still in progress when the second one is made. This is standard behaviour as far as I am aware.

You might want to have the UpdatePanels update together on a button click as opposed to having the update attached to an event on each textbox (it sounds like you have them attached to the blur event). This way you can ensure that lots of requests aren t being made and perhaps disable the button whilst a request is in progress, to prevent a new request from cancelling the one in progress.

EDIT:

You can prevent another request being made form the client side while one request is already in progress by checking the PageRequestManager s isInAsyncPostBack property. Something like the following

function pageLoad(sender, args) {

var pageManager = Sys.WebForms.PageRequestManager.getInstance();

// add a function to execute when an asynchronous postback is initialized
pageManager.add_initializeRequest(checkAsyncPostback);

} 

function checkAsyncPostback(sender, arg)
{
    var pageManager = Sys.WebForms.PageRequestManager.getInstance();
    // check if an async postback is already in progress
    if (pageManager.get_isInAsyncPostBack()) {
        // cancel this async postback if one is currently in progress
        arg.set_cancel(true);
    }
}

There isn t really an easy way to know from the server side if the postback is interrupted.

问题回答

I can t answer your questions specifically, because I don t know how the page manages UpdatePanels and their requests/responses. But, you can probably very easily tell what s going on if you trace the calls with Fiddler. You can see when the requests are firing, and you can see the response as well as if an HTTP error code is sent back or an exception is thrown, etc:

Fiddler2

Look at using the UpdateProgress control: http://www.asp.net/ajax/documentation/live/overview/UpdateProgressOverview.aspx

Also, UpdatePanels are overkill for this kind of thing. Look at using Page Methods (google ASP.NET Page Methods)

EDIT: To further clarify how this would be useful to you, modify the contents of the ProgressTemplate in the UpdateProgress control to display in a modal fashion, so that users cannot do anything until the request completes.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签