Search code examples
c#javascriptjqueryasp.netdopostback

_doPostBack not triggering event


I am trying to hook a jquery style yes|no confirmation box before a button posts back.

What should happen

  • User clicks "no" - no postback
  • User clicks "yes" - postback, button event is triggered

What currently happen

  • User clicks "no" - no postback
  • User clicks "yes" - postback, page load event is triggered, but not button event handler

So, how can I get the button event handler to fire? Right monw it just goes to page load event.

 <asp:Button ID="btnSetActive" runat="server" Text="Set as Active" OnClientClick="AllBrandsConfirmation(); return false;" onclick="btnSetActive_Click" />


$(function () {

    // Set all brands (yes button)
    $('#setAllBrandsConfirmation #yes').click(function () {
        $.unblockUI();
        __doPostBack('ctl00_ctl00_oCPH1_Content_btnSetActive', '');
    });

    // Set all brands (no button)
    $('#setAllBrandsConfirmation #no').click(function () {
        $.unblockUI();
    });

});


// All brands confirmation
function AllBrandsConfirmation() {
    $.blockUI({ message: $('#setAllBrandsConfirmation') });
}

Solution

  • I just figured it out... well google helped :) Apparently in the first argument for the doPostBack method you need to use the controls uniqueId, not the id value. Once I changed that it triggered the event.