当在太短的时间内触发太多时,更新面板的异步触发器会刷新整个页面

发布于 2024-08-28 11:11:09 字数 1106 浏览 3 评论 0原文

我有一个搜索按钮绑定到更新面板作为触发器,如下所示:

<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 以使搜索按钮单击:

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

这工作得很好,除非我开始打字太快。一旦我输入太快(我的猜测是它是否比数据实际返回的速度快),整个页面都会刷新(进行回发?),而不仅仅是更新面板。

我还发现,如果我只是快速单击按钮,而不是打字,它就会开始做同样的事情。

有什么办法可以阻止它这样做吗?在第一个请求完成之前是否可以阻止第二个请求?如果我没有走上正轨,那么有人还有其他想法吗?

谢谢,
马特

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

<asp:Panel ID="CRM_Search" runat="server">
    <p>Search: <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>

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上青苔 2024-09-04 11:11:09

最好做这样的事情,让他喘口气:)

我放置了一个计时器,所以你在发送点击之前等待 250 毫秒。我总是这样做,我从不以正确的方式调用搜索,因为当有人输入一个单词时,实际上程序没有理由一直搜索......

这也将避免您遇到的问题。

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

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

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);            
        }
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文