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.
_doPostBack not triggering event
-
10-12-2021 - |
Question
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 2
OTHER TIPS
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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow