DHTML Tips--Abort the submission of a Web page

Source: Internet
Author: User
Tags commit return thread client
dhtml| Skills | Web page ASP. NET changes our programming method, makes the development BS program simpler. However, if the use of server controls is bound to lead to frequent web page submissions, the operation is extremely unfriendly, but also increased the burden on the server. Some of the necessary validation work is done on the client, only when the validation is submitted, you can significantly reduce the number of page refreshes.





For example, when we press the "delete" button, we first confirm it on the client: a dialog box that pops up "if you really want to delete." When the user presses "yes" to commit to the server to execute the removal program. If no is pressed, the commit action of the thread is terminated. Commit is not to be done too much to consider, because the server's button control is going to be done automatically, and now I'll introduce you to terminate the submission method:





in DHTML, each event can be processed with return False to terminate the execution of the thread action. such as <body OnContextMenu = "Javascript:return false;" > You can disable the right-click menu on the page. For the server button, we can add an onclick property to the Pageload server at the first load time to perform the client corner: this. DELBUTTON.ATTRIBUTE.ADD ("OnClick", "Javascript:return delconfirm ();"); When the user presses the Delete button, it executes the customer's delconfirm () function first. Note: The Javascript:return of the red font (used to receive the return result of the function) and the; (the button's submit action will be registered in the form of a corner), it is necessary if you do not use the number to separate the resulting grammatical errors. In the client's function, there must be a return result, where returns false, the subsequent corner of this operation will be terminated, and the other return results will continue to execute.





the complete method for deleting the processing is as follows:





Server side:





private void Page_Load ()





{





...





if (!this. IsPostBack)





{





...





this.delButton.Attribute.Add ("OnClick", "Javascript:return delconfirm ();");





...


}





...


}





...





private void Delbutton_click (object sender, EventArgs e)





{





...


}





...





Client:





...





<script language=javascript>





function delconfirm ()





{





return confirm ("Do you really want to delete it?");


}





</SCRIPT>





...














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.