0

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!

Ann
  • 61
  • 7
  • Take a look at [ASP.NET Web Application Message Box](https://stackoverflow.com/questions/9720143/asp-net-web-application-message-box). – Étienne Laneville Apr 20 '23 at 03:32
  • This might help too: [How to use jQuery UI Dialog as "confirm before submit" dialog on ASP .NET form](https://stackoverflow.com/questions/12977827/how-to-use-jquery-ui-dialog-as-confirm-before-submit-dialog-on-asp-net-form). – Andrew Morton Apr 20 '23 at 09:52
  • 1
    Gee, you must really hate your users. If I click on a logout button, I am clicking on that button to log out. The fact that you want to THEN nag me to death with a prompt to log out? Gee, don't nag and pester your users to death. Maybe 1 out of a 1000 users will by accident hit the logout. If they did not want to logout, then they can simple log back in. But now you going to nag 1000's of users logging out for 99% of the time when they want to logout, and yet they are to be punished for the 1 in a million users that didn't want to log out? I feel sorry for your users!! – Albert D. Kallal Apr 20 '23 at 14:03
  • @AlbertD.Kallal, you don't know the full specifications. Maybe it's a requirement outside the developer's control. Maybe it's a confirmation only if uncompleted items are outstanding and will be lost if the user is logged out. It IS a worthwhile consideration, from a UX perspective, not to annoy your users, but it isn't the only consideration. – Michael Foster Apr 20 '23 at 14:18
  • If things are not completed in a page? then that is not a log off issue, and a different use case. this post says nothing about wanting a user to complete some data entry, and as such is a different use case. Again: nagging a user due to them clicking on logout is a plain and simple nagging the users to death. What is next, you go to open your car door, and a dialog pops up asking do you really want to open the door? The fact of a user clicking on logout is by its very nature and action implies what the user is attempting to achieve. Different use cases here don't apply and are separate. – Albert D. Kallal Apr 20 '23 at 14:21
  • Hi! Data might be lost when the user accidentally log out. That's why there's a need of confirmation. I – Ann Apr 21 '23 at 11:18
  • And if the user answers yes to logging out, they still will not have saved their data then, right? As I stated, logging out, and that of prompting to save data are 100% different goals here. A prompt to confirm logout still going to result in the user not having saved their data. So, 2 different goals are being mixed up. How is answering yes to a logout going to prevent data loss then? – Albert D. Kallal Apr 22 '23 at 11:59
  • "You have unsaved data! Are you SURE you want to log out? Your work will be lost." can be confirmed, or the user can click No. And your code can first check whether the data is saved; if it is, then no prompt. – Michael Foster Apr 25 '23 at 19:49

1 Answers1

1

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("Confirmation('{0}','{1}');", msg, callback)
        ScriptManager.RegisterStartupScript(Me, Me.GetType, "WindowsScript", confirmScript, True)
    End Sub

Then you need the Javascript:

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

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("__EVENTTARGET") = "Confirmation" Then
                Select Case Request.Params.Get("__EVENTARGUMENT")
                    Case "ConfirmSignOut"
                        DoConfirmationFunctionality()
                End Select
            End If

The DoConfirmationFunctionality should have the code you want to perform.

Michael Foster
  • 420
  • 6
  • 12