My JavaScript code looks like this:
function AutoClickButtons() {
document.getElementById('Button1').click();
document.getElementById('Button2').click();
}
Oddly, only Button2 is being clicked when I run the function. But if I switch the order of the statements, then only Button1 (which is now called second) works.
Just to provide more context, the button clicks trigger ajax calls and partial page updates.
UPDATE: Using setTimeout does solve the issue, but it has a performance drawback. Upon further investigation, I discovered that the two buttons are ASP.NET buttons inside update panels. If I click them consecutively, everything functions properly. However, if I click one quickly followed by clicking the other before the first finishes, the second one succeeds while the first fails. This appears to be a problem specific to update panels and ASP.NET. Is there a way to modify something on that end to make the JavaScript code work seamlessly without relying on setTimeout?