Hidalgo
Hidalgo

Reputation: 941

Call javascript confirm from code behind more than one time

In the ASP.NET code behind I compare some existing and new values and need to ask the User if he/she wants to override. This is done in a loop, for several (more than one) values. Therefore user has to be asked, for each value, to confirm Yes or No. I tried (for testing) putting the following in the loop.

ScriptManager.RegisterStartupScript(this, GetType(), "confirm_yes_no", "confirm('please confirm');", true);

But it only fires once.

Can it be done and how?

Upvotes: 0

Views: 117

Answers (1)

HashPsi
HashPsi

Reputation: 1391

You can register the script using a different script key for each iteration in the loop:

for (var i = 0 ; i < max ; i++) {
  ScriptManager.RegisterStartupScript(
    this, 
    GetType(), 
    "confirm_yes_no_" + i, 
    "confirm('please confirm');", 
    true);
}

Upvotes: 1

Related Questions