The confirmation window (confirm) is displayed in Asp.net to delete the confirmation function.

Source: Internet
Author: User
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";

}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.