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 al开发者_如何学Pythonong 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.
精彩评论