An asynchronous trigger for the update panel refreshes the entire page if it starts up too fast for too short a time

I have a search button attached to the update panel as a trigger:

<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>

In my javascript, I use jQuery to capture the search box and snap it to the keyboard so that the search button clicks:

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

This works fine except when I type too fast. As soon as I type too fast (I think if it is faster than the data will actually return), the whole page is refreshed (by doing a postback?) Instead of the update panel.

I also found that instead of entering text, if I just quickly press a button, it starts to do the same.

? , 2- , ? , - ?

,
Matt

+1
1

- :)

, 250Ms . , , , - , ....

.

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

Source: https://habr.com/ru/post/1743680/


All Articles