0

I have an ImageButton setup, where in the OnInit event, I'm setting the Click event

btnJoinNow.Click += new ImageClickEventHandler(btnJoinNow_Click);

On the client-side, I have setup a jQuery click event which is to fire of a hitwise tracking event only when the button is pressed. The problem I'm having is that it seems that the button event is beating the javascript and not tracking. I need to put a pause of 1 sec before the imagebutton event fires server-side.

I've tried the following, but always fires. I've also tried e.preventDefault(), but that just stops the postback altogether.

$("input[id$='btnJoinNow']").click(function(e) {
    Spots.HitWise();

    setTimeout(function(){
    }, 5000);
});

EDIT:

The only way I could get this to work, was by doing the following:

$("input[id$='btnJoinNow']").click(function(e) {
    Spots.HitWise();

    setTimeout(function(){
       $("input[id$='btnJoinNow']").unbind('click').bind('click', function(e){});
    }, 1000);

    return false;
});

This then allows enough time for the HitWise event to track, then clears the click event and calls itself again.

mickyjtwin
  • 4,960
  • 13
  • 58
  • 77

1 Answers1

1

use OnClientClick

<asp:ImageButton id="btnTest" runat="server" 
      OnClientClick="javascript:FireHitwise();" .../>

<script type="text/javascript">
function FireHitwise(){
    Spots.Hitwise();
    return true;//returning false will not fire server side handler
}
</script>
TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
  • the problem with this, is that the hitwise event does not have time to fire. The return true and subsequent postback beat the tracking event. Even putting a javsacript delay does not work. I've resort to firing the event on the next page so it loads on page load and does not have to worry about timing issues. The only way I could get it to work previously is above in my edit – mickyjtwin Jan 10 '11 at 05:49