What is wrong in the below code?
ClientScript.RegisterStartupScript(
Me.GetType(),
"key",
"return confirm('Are you sure you wish to delete these records?');",
True)
What is wrong in the below code?
ClientScript.RegisterStartupScript(
Me.GetType(),
"key",
"return confirm('Are you sure you wish to delete these records?');",
True)
You are registering a startup script; a startup script is intended to be run (no surprise) on startup. By itself, your code cannot be run on startup--there is nothing logical for it to do, i.e. where would it return?
However, JavaScript code outside of a function is legal in many cases. The following code would work fine.
Example (VB.NET)
ClientScript.RegisterStartupScript(
Me.GetType(),
"key",
"alert('I am a client-side script!');",
True)
Your particular code either needs to be put into a function and called when desired, or attached to a client-side event.
Since the intention is a delete prompt, here is an example attached to btnDelete.
Example (C#)
this.btnDelete.Attributes["onclick"] = "return confirm('Are you sure you wish to delete these records?');";