引发过短的时间过多时异步触发更新面板刷新整个页面 [英] Async trigger for an update panel refreshes entire page when triggering too much in too short of time

查看:287
本文介绍了引发过短的时间过多时异步触发更新面板刷新整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绑在一个更新面板,像这样一个触发搜索按钮:

I have a search button tied to an update panel as a trigger like so:

<asp:Panel ID="CRM_Search" runat="server">
    <p>Search:&nbsp;<asp:TextBox ID="CRM_Search_Box" CssClass="CRM_Search_Box" runat="server"></asp:TextBox>
    <asp:Button ID="CRM_Search_Button" CssClass="CRM_Search_Button" runat="server" Text="Search" OnClick="SearchLeads" /></p>
</asp:Panel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="CRM_Search_Button" />
    </Triggers>
    <ContentTemplate> 
     /* Content Here */
    </ContentTemplate>
</asp:UpdatePanel>

在我的JavaScript使用jQuery抢搜索框和领带是KEYUP使搜索按钮点击:

In my javascript I use jQuery to grab the search box and tie it's keyup to make the search button click:

    $($(".CRM_Search_Box")[0]).keyup(
        function () {
            $($(".CRM_Search_Button")[0]).click();
        }
    );

这完美的作品,除了当我开始打字太快了。当我键入​​太快(我的猜测是,如果它比任何数据快​​实际上返回)整个页面刷新(做回发?),而不是仅仅更新面板。

This works perfectly, except when I start typing too fast. As soon as I type too fast (my guess is if it's any faster than the data actually returns) the entire page refreshes (doing a postback?) instead of just the update panel.

我还发现,而不是打字,如果我只是按一下按钮真快它开始做同样的事情。

I've also found that instead of typing, if I just click the button really fast it starts doing the same thing.

有什么办法prevent它这样做呢?直到第一个已完成可能prevent第二个请求?如果我没有在正确的轨道上,然后任何人有任何其他的想法?

Is there any way to prevent it from doing this? Possibly prevent 2nd requests until the first has been completed? If I'm not on the right track then anyone have any other ideas?

谢谢,

马特

Thanks,
Matt

推荐答案

它是更好地做这样的事情,并给他一口气:)

Its is better to do something like that, and give him a breath :)

我把一个计时器,让你等待250MS其发送前点击。我总是这样做,我永远不会调用搜索正确的方式,因为当有人输入一个词,其实是没有理由的程序来搜索所有的时间....

I place a timer, so you wait for 250Ms before its send the click. I always do that, I never call the search right way because when some one type a word, actually there is no reason for the program to search all the time....

这也将避免你的问题,你有。

Also this will avoid your problem that you have.

var hTimeOut = null;
$($(".CRM_Search_Box")[0]).keyup(
        function () {
            if(hTimeOut)
                clearTimeout(hTimeOut);
            hTimeOut = setTimeout(function() { $($(".CRM_Search_Button")[0]).click(); }, 250);            
        }
);

这篇关于引发过短的时间过多时异步触发更新面板刷新整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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