The confirmation button is often displayed during webpage creation, especially when you delete a database. If you do not set this button, data will be lost. If a confirmation button is provided, the user will be given a remediation opportunity to avoid unnecessary data loss. If you use JS directly, it is difficult to contact the background operations.
Solution:
Add the attributes attribute to the button, that is, button1.attributes ["onclick"] = "Return confirm ('Are you sure? ')";
In this way, the onclick = "Return confirm ('Are you sure? ') "When the user executes the button operation, a confirmation window of confirm is displayed locally. Then, based on the user's selection, the user determines whether to execute the button operation. At the beginning, I thought how the server knows the user's choice. In fact, when I click "cancel", the client will confirm it by itself, it is not sent to the server for confirmation.
The following is an example.
. Aspx Code < Form ID = " Form1 " Method = " Post " Runat = " Server " >
< Font face = " " >
< ASP: button ID = " Button1 " Runat = " Server " Text = " Button " > </ ASP: button >
< ASP: Label ID = " Label1 " Runat = " Server " > Label </ ASP: Label > </ Font >
</ Form >
. CS code
Private Void Page_load ( Object Sender, system. eventargs E)
{
// Place user code here to initialize the page
Button1.attributes [ " Onclick " ] = " Return confirm ('Are you sure? ') " ;
Label1.text = " Are you sure " ;
}
Private Void Button#click ( Object Sender, system. eventargs E)
{
Label1.text="I'm sure";
}
}