取消javascript按钮关闭弹出窗口。

时间:2013-10-16 14:36:16

标签: javascript asp.net .net vb.net

在一个模态弹出窗口中,我正在更新值,并在点击保存按钮后,在更新之前我通过javascript消息框询问用户:“你确定......?”

我正在通过以下代码来做:

 btnSave.Attributes.Add("onclick", "javascript:return " & "confirm('Are you sure " & RbtnConfirm.SelectedValue & " ' )")

但是当用户点击取消时,我想通过以下方式关闭整个模态弹出窗口:

modalpopup1.hide()方法

我很困惑我应该如何以及在哪里包含这行代码?

我可以从哪里获得btnSave.Attributes.Add("onclick", "javascript:return " & "confirm('Are you sure " & RbtnConfirm.SelectedValue & " ' )")是否返回false或true?

请帮帮我。

2 个答案:

答案 0 :(得分:1)

将确认调用移至单独的功能,即:

在.ascx / .aspx中包含此内容:

<script>
  function myconfirm(sValue) {
     var bValue = confirm(sValue);
     if (!bValue) {
       modalpopup1.hide();
     }
     return bValue;
  }
</script>
代码隐藏中的

btnSave.Attributes.Add("onclick", "javascript:return " & "myconfirm('Are you sure " & RbtnConfirm.SelectedValue & " ' )")

答案 1 :(得分:1)

为什么return " & "

无论如何,对于内联(不推荐),只需执行

btnSave.Attributes.Add("onclick", "if (confirm('Are you sure " & RbtnConfirm.SelectedValue & " ' )) modalpopup1.hide()")