ASP.NET 服务器端的确认对话框

ASP.NET Confirmation dialog on server side

本文关键字:确认 对话框 服务器端 NET ASP      更新时间:2023-09-26

我有一个页面,它从用户那里获取输入,然后在单击按钮时处理他的请求。在此按钮单击事件中,我需要验证他输入的输入,并在某些条件下显示确认对话框。如果他单击"是",那么我需要执行进一步的操作,否则返回。

我试过使用

Page.ClientScript.RegisterStartupScript(this.GetType(), Constants.OpenConfirm, "confirm('Data Already Exists, do you Wish to Overwrite the existing record?')", true);

但是,无论我单击"是"还是"否",它都会执行进一步的操作。

已经尝试过从服务器端使用 JavaScript 方法调用,但这也没有奏效。

您需要处理确认调用的结果。所以脚本参数必须是这样的:

if(!confirm('Data Already Exists, do you Wish to Overwrite the existing record?')) return false;

试穿page_load .cs

ClientScript.RegisterStartupScript(GetType(), "Javascript", 
"javascript:if(confirm('Are you sure?')) {  alert('YOu have selected YES')} else{alert('you have click NO')}; ", true);

试试这个方式:服务器端代码

this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Javascript", "Javascript:val()", true);

客户端代码

<head runat="server">
    <title></title>
    <script>
        function val() {
            if (confirm('XXXXYYYY?')) { alert("clicked yes") } else { alert("clicked No") }
        }
    </script>
</head>