Difference between registerstartupscript and registerclientscriptblock

Source: Internet
Author: User

Both methods are used to write scripts from the background to the foreground, and both of them accept two strings as input. The first parameter key is the unique identifier of the inserted client script, and the second parameter script is the client script to be inserted to the page, including the start and end tags of the <SCRIPT>.

The only difference between the two methods is that the script block is sent from "where. Registerclientscriptblock () sends the script block at the beginning of the web form (followed by the <form runat = "server"> identifier), while registerstartupscript () the script block is sent at the end of the web form (before the </form> identifier.

Registerstartupscript () is used to add the script block to run after the page is loaded. The script block added in this way is located at the end of the web form, because the HTML elements to be modified must be defined before the script runs. That is, if you want to use a client script to set the focus to the text box, make sure that the HTML mark of the text box is before the script that sets the focus of the text box.

The registerclientscriptblock () method is used to execute scripts in response to client events.Code. The script block sent using this method is located at the beginning of the web page, because this method does not require that the script block be placed after all HTML elements, that is, it generally does not use custom controls in the document.

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.