Why does concurrent calls to window.confirm fail?

Coreysan 1,811 Reputation points
2021-07-24T00:54:32.4+00:00

In my aspx project, I use javascript's window.confirm to prompt the user for various things. (I'll use a 3rd party package later - for now, my boss wants it this way.)

So, when a user clicks on the Update button, I use window.confirm(....) to confirm the update, then I update a database, and then I want to call window.confim(....)
one more time to tell the user the update was successful.

I make the javascript calls using ScriptManager.RegisterStartupScript(.....).

Well, it appears if I call ScriptManager more than once in a method, it only runs the first call, and blows right past the second call.

It roughly looks like this:

string wmsg = "Are you sure?";
string PassMsg = "ShowConfirmed('" + wmsg + "');";
ScriptManager.RegisterStartupScript(this, this.GetType(), System.Guid.NewGuid().ToString(), PassMsg, true);

Update_the_Database();

string wmsg = "Update sucessfull!";
string PassMsg = "ShowConfirmed('" + wmsg + "');";
ScriptManager.RegisterStartupScript(this, this.GetType(), System.Guid.NewGuid().ToString(), PassMsg, true);

Is there anything here that shows I'm doing something wrong?

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

Accepted answer
  1. Yijing Sun-MSFT 7,096 Reputation points
    2021-07-26T06:30:45.353+00:00

    Hi @Coreysan ,
    Yes,I think you could confirm before the postback. I have another way: you could split them into individual separate functions.For example: you could click update button to update the database and call the confirm of "sucessfull".
    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Bruce Barker 801 Reputation points
    2021-07-25T17:09:44.557+00:00

    RegisterStartupScript does not run the script, it adds the script code to the response html. All the server code will run, then send the html response, then the client code will run.

    To do what you want you would need to break the request into two requests. The first would pop up the first alert. This would take some JavaScript, and a better approach would be for client code to do the confirm before the postback.

    0 comments No comments

  2. Coreysan 1,811 Reputation points
    2021-07-27T20:09:43.23+00:00

    Thanks to both of you. I wish I could give you both an "accept answer!" I solved my problem, because of you both.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.