In Asp.net webfrome, add a confirmation box for the button

Source: Internet
Author: User

Due to work requirements, I am not very familiar with my own MVC technology, especially in JS. All of them are transferred back to webfrom development (in fact, each has its own advantages ).

A simple function is to add a confirmation prompt box for the button control. I remember that the confirmation box was added in the background:

Btnxxx. Attributes. Add ("onclick", "If (! Confirm (Are you sure you want to delete it? ') {Return false ;}");

But it was very strange that I did not respond when I added it. Then I found a simpler method:

<Asp: button id = "button1" runat = "server" text = "button"
Onclientclick = "Return confirm ('Are you sure you want to submit? '); "Onclick =" button#click "/>

Onclick triggers server events. The script is C # Or VB. NET.

Onclientclick triggers client events. The script is generally Javascript. This attribute is added to ASP. NET 2.0. Before 1.1, you must add the attribute to add client events.

When you click the button, first run the script in onclientclick. If the return value is true, then run the code in button_onclick. Otherwise, the background code of the button will not be executed.

Simple and Convenient. Why didn't I see it before?

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.