在这里阅读了多篇文章并尝试使我的代码正常工作后,并没有真正帮助我。我想要完成的是当用户单击对话框消息中的“确定”按钮时从 noty 获取返回值。我想在 C# 代码隐藏中获得该值并继续进一步的逻辑。Messagedialog 正在按预期工作和显示,但是当用户单击“确定”时,我无法弄清楚如何获得真/假。提前致谢!
<asp:Button ID="btnInactivate" runat="server" Text="Inactivate" OnClick="btnInactivate_Click" Visible="false" CssClass="buttonInactivate"/>
protected void btnInactivate_Click(object sender, EventArgs e)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "script", "confirm_noty();", true);
var retValue = noty........
// get the value from noty
// button ok pressed ... continue with further process....
}
function confirm_noty() {
var n = noty({
layout: 'center',
type: 'warning',
text: 'Do you want to inactivate current record?',
dismissQueue: true,
theme: 'defaultTheme',
modal: true,
buttons: [
{
addClass: 'btn btn-primary', text: 'Ok', onClick: function ($noty) {
// this = button element
// $noty = $noty element
$noty.close();
noty({
dismissQueue: true, force: true, layout: 'center', theme: 'defaultTheme', text: 'Record successfully inactivated.', type: 'success',
"animateClose": { "height": "toggle" }, "speed": "550", "timeout": "1200", "closable": true, "closeOnSelfClick": true
});
}
},
{
addClass: 'btn btn-danger', text: 'Cancel', onClick: function ($noty) {
$noty.close();
}
}
]
});
}