关闭页面前的确认消息(asp.net,vb.net,webapp)

huangapple go评论66阅读模式
英文:

Confirmation Message before closing the page (asp.net, vb.net, webapp)

问题

I know message box is only for window apps, but what about for web apps. I would like to ask help on how to do this on web apps, confirm first from the user when he/she clicks [Sign out] button, if he/she really wants to sign out with a [yes] or [no] button. Thank you!

英文:

I know message box is only for window apps, but what about for web apps. I would like to ask help on to do this on web apps, confirm first from the user when he/she clicks [Sign out] button, if he/she really wants to sign out with a [yes] or [no] button. Thank you!

答案1

得分: 1

以下是翻译好的部分:

你不能在代码后台完成这项任务,因为客户端与用户进行交互,而不是与服务器交互。尽管如此,你可以为客户端提供执行所需操作的指令。你只需将它与Javascript结合使用。

然后,你需要Javascript部分:

<script type="text/javascript">
    function Confirmation(message, target) {
        if (confirm(message)) {
            __doPostBack("Confirmation", target);
        }
    }
</script>

最后,在 Page_Load 中,检查确认是否已确认:

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    If IsPostBack Then
        If Request.Params.Get("__EVENTTARGET") = "Confirmation" Then
            Select Case Request.Params.Get("__EVENTARGUMENT")
                Case "ConfirmSignOut"
                    DoConfirmationFunctionality()
            End Select
        End If
    End If
End Sub

DoConfirmationFunctionality 应该包含你要执行的代码。

英文:

You (sort of) can't do this in code-behind, because the client interacts with the user, not the server. That said, you can give instructions for the client to do what you want. You just have to combine it with Javascript.

    Protected Sub ConfirmBox(msg As String, callback As String, title As String)
        Dim confirmScript As String = String.Format(&quot;Confirmation(&#39;{0}&#39;,&#39;{1}&#39;);&quot;, msg, callback)
        ScriptManager.RegisterStartupScript(Me, Me.GetType, &quot;WindowsScript&quot;, confirmScript, True)
    End Sub

Then you need the Javascript:

    &lt;script type=&quot;text/javascript&quot;&gt;
        function Confirmation(message, target) {
            if (confirm(message)) {
                __doPostBack(&quot;Confirmation&quot;, target);
            }
        }
    &lt;/script&gt;

Finally, in Page_Load, check if your confirmation is confirmed:

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            If Request.Params.Get(&quot;__EVENTTARGET&quot;) = &quot;Confirmation&quot; Then
                Select Case Request.Params.Get(&quot;__EVENTARGUMENT&quot;)
                    Case &quot;ConfirmSignOut&quot;
                        DoConfirmationFunctionality()
                End Select
            End If

The DoConfirmationFunctionality should have the code you want to perform.

huangapple
  • 本文由 发表于 2023年4月20日 07:10:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76059451.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定