简体   繁体   中英

_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') });
}
protected void Page_Load(object sender, EventArgs e)
{
    if(Request.Form["__EVENTTARGET"] != null)
        if(Request.Form["__EVENTTARGET"] == "ctl00_ctl00_oCPH1_Content_btnSetActive")
            btnSetActive_Click(sender, e);
}

protected void btnSetActive_Click(object sender, EventArgs e)
{
    //do your work here
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM