开发者

Hitwise tracking on ImageButton click event in ASP.NET

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 pau开发者_JS百科se 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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜