如何在按钮点击结果后显示是/否警告框使用C#? [英] How to show yes/no alert box use C# after buttonclick result?

查看:81
本文介绍了如何在按钮点击结果后显示是/否警告框使用C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have used below function in inside the button click after the success message come continue our further process if not come success to show the popup with yes/no if click no process is stop click no stop the process.but the below code the script is show after the process is completes how to do it?





我的尝试:





What I have tried:

ASPX
 
 <script type = "text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Do you want to save data?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>
 
 
 
Code Behind
 
 
protected bool ValidateDuplicate()
{
bool result = true;
Material material = new Material();
MaterialDataAccess materialDA = new MaterialDataAccess();
if (hfdMode.Value.Equals("new") || hfdMode.Value.Equals("draft"))
{
material.Type = "N";
}
else if (hfdMode.Value == "update")
{
material.Type = "U";
}
material.RequestNo = hfRequestNo.Value;
material.Description = tbxShortDescription.Text.ToUpper().Replace("'", "''");
materialDA.Material = material;
materialDA.ValidateCheck();
if (!materialDA.Message.Text.Equals("SUCCESS"))
{
ClientScript.RegisterStartupScript(typeof(Page), "Confirm", "<script type='text/javascript'>callConfirm();</script>");
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
// event occures
}
else
{
// do nothing
}
}
return result;
}

推荐答案

RegisterStartupScript不会停止服务器端执行以在客户端上运行脚本并等待响应,它所做的只是将您指定的javascript添加到输出并继续。在您的所有服务器代码完成运行后,浏览器只获取html(因此运行js)。有几种方法可以处理确认以继续执行某些操作,可能需要将您的任务分成两个不同的步骤。



要求用户确认他们想要继续一个动作| ASP.NET论坛 [ ^ ]



你正在使用的技术不能固定,你将不得不重新设计你的过程。
RegisterStartupScript isn't stopping server-side execution to run script on the client and wait for a response, all it is doing is adding the javascript you specify to the output and continues on. The browser only gets the html (and therefore runs the js) after all of your server code has finished running. There are a few ways to handle getting a confirmation to continue something, it might involve splitting your task into two distinct steps.

Asking the user to confirm that they want to continue with an action | The ASP.NET Forums[^]

The technique you're using can't be "fixed", you're going to have to re-architect your process.


这篇关于如何在按钮点击结果后显示是/否警告框使用C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆