About form submission issues for multi-commit buttons (judge the clicked button with client code)

xiaoxiao2021-03-06  49

Problem Description: Suppose there is a message board, there is "Reply" and "Delete" 2 functions in the administrator page, click the reply to directly submit the reply operation, but you need to pop up a confirmation box when you click Delete, but when the user confirms Submit the execution delete operation. Obviously, you need to use the client script.

Here is my approach: server side: use VB.NET client: Applicable JavaScript

The partial code of the form is as follows:

... ... Because the form has 2 buttons, it is necessary to judge the commit button before the form is submitted. You can use the following statement Event.srcelement.id or event.srcelement.value to determine which button is submitted. At first, you might think this judgment should be written in the InputValidate () function, and it is judged when the form is submitted. But actually this is not, because the source of the event we need is the submission button, then this judgment can only write the button's Click event function. But do this control form submission, because the submit is submitted by the form is the Submit event function. Fortunately, the Click event happens before the submit event, this has the following solution: set an intermediate variable, saved event.srcelement.id or event.so when the Click event occurs, after the submit This intermediate value is judged in the event and then takes different actions. code show as below: