This has been already asked by many SO users and have solutions also. But none of them is working for me.
In aspx
<asp:Button ID="btnConfirm" ClientIDMode="Static" runat="server" Text="Confirm" OnClick="btnConfirm_Click"/>
<script type="text/javascript">
$(function inPageLoad() {
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function () {
//Confirmation Dialog
$(document).on('click', '#btnConfirm', function (e) {
e.preventDefault();
$('<div></div>').appendTo('body')
.html('<div><h6>Yes or No?</h6></div>')
.dialog({
modal: true, title: 'message', zIndex: 10000, autoOpen: true,
width: 'auto', resizable: false,
buttons: {
Yes: function () {
$(this).dialog("close");
__doPostBack('btnConfirm','');
},
No: function () {
$(this).dialog("close");
}
},
close: function (event, ui) {
$(this).remove();
}
});
});
});
});
$(document).ready(inPageLoad);
</script>
In aspx.cs
protected void btnConfirm_Click(object sender, EventArgs e)
{
SomeFunction();
}
I want to do a postback(go to 'btnConfirm_Click' event in codebehind) if the click is 'Yes'. Eventhough the dialog popups nicely it doesn't do the postback. All help appreciated!
instead of __doPostBack('btnConfirm','')
;
Yes: function () {
$("[id*=btnConfirm]").click();
},
UPDATING MY ANSWER
Take another button, with display none property and trigger that Button
css
.hidden
{
display:none;
}
aspx
<asp:Button id="btnhidden" runat="server" onclick="btnhidden();" cssClass=hidden/>
javascript
Yes: function () {
$("[id*=btnhidden]").click();
},