question

CoreyFleig-6304 avatar image
0 Votes"
CoreyFleig-6304 asked CoreyFleig-6304 answered

Why does concurrent calls to window.confirm fail?

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?



dotnet-aspnet-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered

Hi @CoreyFleig-6304 ,
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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

BruceBarker-8516 avatar image
0 Votes"
BruceBarker-8516 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CoreyFleig-6304 avatar image
0 Votes"
CoreyFleig-6304 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.