0

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');"/>
DJ Burb
  • 2,346
  • 2
  • 29
  • 38
  • 2
    I tested the button and it works fine in Chrome. Maybe some other piece of code is interfering? – VDWWD Jul 03 '19 at 14:50
  • Just seems strange that it would work when there is no Text property vs having a Text property – DJ Burb Jul 03 '19 at 14:53
  • You have client side behavior on a server side button. It's probably trying to submit the form, though it's been awhile since I've worked with webforms. How about instead of using a "real" submit button, since you're trying to allow for it to not submit without confirm, you make a little function called onClientClick that just does that for you? (remove the onclick and runat server) – Nikki9696 Jul 03 '19 at 16:14

1 Answers1

1

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

  • This sounds like a clue because I did notice something about "Waiting to Load Facebook.. yadayada" on the bottom of the page. let me check it out – DJ Burb Jul 05 '19 at 16:25
  • Do you happen to have the actual line of code you deleted? – DJ Burb Jul 05 '19 at 16:30
  • Yep!!! good ol' Google Analytics. I went through and commented out all the code that involved Google Analytics and it worked. Like you said, it is not the final solution, but it is good to know that has nothing to do with our direct code. I am going to accept your answer and see if I can find a workaround for this issue. Thanks!!! – DJ Burb Jul 05 '19 at 16:48
  • @DJBurb where you able to find a solution which does not involve removing GA / GTM ? – hoektoe Jul 17 '19 at 09:36
  • @hoektoe Nope. So far that is the only solution on our side. The funny thing it doesn't happen to everybody. It's not consistant across machines. – DJ Burb Jul 17 '19 at 14:52
  • 1
    @DJBurb check if they other available computers using chrome has any ad-blocking enabled. For myself on my pc: 1) With ad-blocking enable confirm() and alert() works 100% as fbevents and other scripts via GTM is blocked. 2) Same chrome browser with adblock ( ublock ) disabled, then confirm and alert() does NOT work. In our situation we cannot remove GTM, so for internal staff we have enabled ad-blocking. Looking for solution for external clients to that portal where GTM is a must. – hoektoe Jul 18 '19 at 15:15
  • @hoektoe We are in the same situation. Our application is customer facing. I don't know if telling the customer to enable ad-blocking is an option or not, but this is a good heads up. Thanks – DJ Burb Jul 19 '19 at 16:03
  • I've forwarded the problem to our marketer who handles GTM. She said: after trying to turn on and off everything she finally got to the point: she disabled facebook pageview tracking. As it was kinda useless, it's not a problem disabling it, and the problem is elliminated. I don't know if it could be an option for you or not,... – Gyürüs Máté Jul 19 '19 at 18:45
  • Yes we disabled facebook pixel to automatically send button information, https://developers.facebook.com/docs/facebook-pixel/advanced/#automatic-configuration This will fix the problem of alert() dissapearing or automatically closing – hoektoe Jul 29 '19 at 07:20