Warm tip: This article is reproduced from stackoverflow.com, please click
asp.net html input javascript

window.confirm disappears without interaction in Chrome

发布于 2020-03-27 10:21:52

I have an ASP button that when clicked brings up a window.confirm. This window.confirm disappears without user interaction. However, if I keep clicking the ASP button, after about the 4th or 5th click the window.confirm box will work as expected.

A couple of things that I also noticed, after hours of working on it, if I remove the Text property from the ASP button, the window.confirm works as it should.

This made me think, "Hmmmm... let me look at the <input> button that is behind the scenes of the ASP button, and I noticed that if I remove the value from the input the window.confirm works, but if I put a value in the input, the window.confirm stops working again.

Does anyone know what may cause this? Is there a work around to putting text in the button without using the Text property? I haven't tried innerHTML yet because I wanted to see if there is anything else I can do before I do that.

Btw, I tried using OnClientClick, instead of OnClick and I get the same results.

Here is the code that I have for the button:

<asp:Button ID="btSubmit" runat="server" Text ="Submit Email" OnClick="btSubmit_Click" OnClientClick="return confirm('Test');"/>
Questioner
DJ Burb
Viewed
79
Gyürüs Máté 2019-07-04 13:40

I've just faced the same issue. As investigating the problem I've found out that the code itself is ok, but after puting it in the context of the website - starts failing as described above. The problem seems to be the facebook tracking code called through GTM. If I remove the whole Google Tag manager code from the header - everything just works fine

Although it's not the sollution yet, so I'll need some deeper GTM investigation to prevent this behaviour. But this also might help you...