ASP.Net的自动回发.如果速度太慢会怎样? [英] ASP.Net's auto-postback. What happens when its too slow?

查看:102
本文介绍了ASP.Net的自动回发.如果速度太慢会怎样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Web应用程序.我在更新面板时遇到了一个奇怪的错误.

好,假设您有两个更新面板,每个更新面板中都有一个文本框.这两个文本框都是自动回发的,更新面板有条件地更新.

好吧,从我观察到的行为看来,如果服务器处理请求的速度不比用户快,那么它在客户端就被忽略了. 就像说您在其中一个文本框中键入内容,然后快速跳至下一个文本框并键入内容并跳出.这应该导致2次发帖.

那么,如果服务器正在处理1个回发而又发生了一个回发怎么办?该回发是否在服务器端或客户端丢失?

我在这种情况下观察到的主要问题是,第一次发生回发时,有一个Update()用于更新面板.好吧,当第二次发回中断第一次发回时,它还会在更新面板(一个不同的面板)上执行更新".用户看到的是,如果他们快速浏览(或服务器处于高负载或其他任何情况),则第二个更新面板将被更新,而不是第一个.

tl; dr:当回发中止另一个回发时,假定是在第一次回发中进行更新的任何更新面板都不会得到更新(尽管第二次回发是) >

如何解决此问题或解决该问题?我无法更新屏幕上的所有更新面板,因为这样用户当前所在的控件将失去注意力,并且失去了很多注意力其他问题.

解决方案

UpdatePanels拦截回发并使用XMLHTTPRequest对象(即,他们使用AJAX)向服务器发出请求.

如果第二个XMLHTTPRequest仍在进行中,则它将取消第一个XMLHTTPRequest.据我所知,这是标准行为.

您可能希望在单击按钮时将UpdatePanels同时更新,而不是将更新附加到每个文本框上的事件(听起来像是将它们附加到blur事件上).这样,您可以确保不会发出大量请求,并可以在进行请求时禁用该按钮,以防止新请求取消正在进行的请求.

通过检查PageRequestManagerisInAsyncPostBack属性,可以防止在一个请求正在进行时从客户端发出另一个请求.类似于以下内容

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);
    }
}

从服务器端知道回发是否被中断真的不是一种简单的方法.

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.

这篇关于ASP.Net的自动回发.如果速度太慢会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆