0

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

Nadlir
  • 15
  • 6
  • You can make use of some boolean variable and set it to true if one event is happening , and when you try to do the other , if first checks the value of that variables and decide based on that – Harmandeep Singh Kalsi Jun 20 '20 at 17:57
  • Unfortunately it doesn't work, since each time one action is "open" the other one is blocked being occured till the first one is "closed". So when one action is "open" the other one doesn't even gets to get into its code and check if the other one is heppening. – Nadlir Jun 20 '20 at 18:59
  • Your counter is in fact a button being pressed as well, so you have two buttons being pressed at the same time, one will block the other, javascript is single threaded, one event is taking precedence over the other. – shadownrun Jun 20 '20 at 20:22
  • Yea, I wonder why do they block each other ? My assumption is that each one of them causes a postback, and whenever a postback is occuring, the timer is reseted, causing the counter stop. – Nadlir Jun 20 '20 at 20:25
  • I'm not familiar with .net, but if the "page" is being reloaded yes the timer is reset – shadownrun Jun 20 '20 at 20:37
  • Is there any way to prevent button causing postback ? – Nadlir Jun 20 '20 at 20:38

0 Answers0