[英]open a confirmation dialog from code behind
I have a button click event and in that after satisfying some condition , i should confirm dialog, if user clicks ok in that dialog, i want to proceed further in my code. 我有一个按钮单击事件,在满足一定条件后,我应该确认对话框,如果用户在该对话框中单击“确定”,则我想在代码中继续进行。
public void imgValidAdd_Click(object sender, ImageClickEventArgs e)
{
try
{
// Some Code
if(A==b)
{
// Open Confirm dialog
if(ok)
{
// Proceed
}
}
}
catch()
{
}
}
I have tried so many approaches, but nothing worked out 我尝试了很多方法,但没有解决
How to call confirm message from code behind in asp.net? 如何从asp.net后面的代码中调用确认消息?
in the above link, i tried and implemented but the thing is ,if you don't postback the page, it doesn't work because appendChild command doesn't clear previous values 在上面的链接中,我尝试并实现了,但问题是,如果您不回发页面,则此操作将无效,因为appendChild命令不会清除先前的值
How do i work on this. 我该如何处理。 help me on this. 帮助我。
You can do something like this: 您可以执行以下操作:
On aspx side 在aspx方面
1) add a button for confirmed clicked 1)添加按钮以确认单击
hidden button
<asp:Button ID="btnConfirmed" runat="server" OnClick="btnConfirmed_Clicked" style="display:none"/>
2) add a javascript function for confirm dialog 2)添加用于确认对话框的javascript函数
//Add a javascript openconfirmdialog() on aspx
function openconfirmdialog() {
if(confirm('Confirm message')) {
//fire hidden button click
$('#<%=btnConfirmed.ClientID%>').click();
} else {
//else message
}
}
On aspx.cs server side 在aspx.cs服务器端
3) fire javascript function from server side using Page.ClientScript 3)使用Page.ClientScript从服务器端触发javascript函数
public void imgValidAdd_Click(object sender, ImageClickEventArgs e)
{
try
{
// Some Code
if(A==b)
{
// Open Confirm dialog
Page.ClientScript.RegisterStartupScript(typeof(Page), "openconfirmjs", "<script>openconfirmdialog();</script>");
}
}
catch()
{
}
}
4) Add a confirm button click method 4)添加确认按钮的点击方法
public void btnConfirmed_Clicked(object sender, EventArgs e) {
// Proceed
}
You could use window.confirm 您可以使用window.confirm
https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm https://developer.mozilla.org/zh-CN/docs/Web/API/Window/confirm
if (window.confirm("Do you really want to ___?")) {
// do thing
} else {
// don't do thing?
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.