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?