1

我有一个页面,它接受用户的输入,然后通过单击按钮处理他的请求。在此按钮单击事件上,我需要验证他输入的输入,并在某些情况下显示确认对话框。如果他单击是,那么我需要执行进一步的操作,否则返回。

我试过使用

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

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

已经尝试使用从服务器端调用的 JavaScript 方法,但这也行不通。

4

3 回答 3

1

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

if(!confirm('Data Already Exists, do you Wish to Overwrite the existing record?')) return false;
于 2013-10-16T09:40:54.133 回答
0

尝试 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);
于 2013-10-16T10:02:55.117 回答
0

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

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>
于 2013-10-16T09:55:18.650 回答