Click on a button pauses other function interval

守給你的承諾、 提交于 2020-06-29 04:45:13

问题


So I have a button (called here "LeftArrow") and a counter label (called here "lbl") (they are not connected to each other in any way). The counter is working by those codes :

<script>
    
        function check() {
            document.getElementById("UpdatePlayersInPartyBTN").click();
        }
        setInterval(check, 1000);


</script>

There is this button that occurs the code-behind by the JS function :

<button runat="server" id="UpdatePlayersInPartyBTN" onserverclick="UpdatePlayersInParty" hidden="hidden"> </button>

And the code-behind is this (lbl is the counter label) :

protected void UpdatePlayersInParty(object sender, EventArgs e)
{
        string s1 = lbl.Text;
        lbl.Text = (int.Parse(s1) + 1).ToString();
}

And in addition to all those , I have got this button :

<button runat="server" id="LeftArrow" onserverclick="LeftArrow_Click" class="btn3">
            <i class="fas fa-arrow-left"></i>
</button>

My problem is this - those 2 events (clicking on "LeftArrow" button , and updating the counter), can not heppen in the same time (lets say, if I'm spamming the "LeftArrow" button, the counter stops, and vice versa - if im clicking the button the same moment that the counter occur - the button click won't occur).

Is there any idea why could it heppen ? Thanks to all :)

来源:https://stackoverflow.com/questions/62489483/click-on-a-button-pauses-other-function-interval

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!