Minor issues with scipt in Asp.net

Source: Internet
Author: User

The problem that was first encountered when JavaScript was used to transform the image module was discovered by accident. At that time, the problem was that the elements on the document could not be found. The reason is that"

We have introduced two different methods for embedding JavaScript Functions into ASP. NET pages. What is the difference between them? The main difference is that the registerstartupscript method embeds JavaScript at the bottom of the ASP. NET page, just before the close element </form>. The registerclientscriptblock method embeds Javascript into the end of the <form> element that is enabled on the page. So what's the difference? As we will see, this is a big difference.

Here is an example. Here is how to focus on a text box on the page when the page is loaded to a browser-Use Visual Basic that uses the registerstartupscript method:

Page. clientscript. registerstartupscript (Me. GetType (), "testing", _ "document. Forms [0] ['textbox1']. Focus ();", true)
When the browser runs at the bottom of the page and executes this small JavaScript code, a text box on the page is generated and placed on the page. Therefore, this method runs normally. However, if you do not follow the above method, write the following:Code(Use the registerclientscriptblock method ):

Page. clientscript. registerclientscriptblock (Me. GetType (), "testing", _ "document. Forms [0] ['textbox1']. Focus ();", true)
The text box control does not get the focus and generates a javascript error on the page.

The error occurs because the browser encounters JavaScript before the text box appears on the page. Therefore, textbox1 cannot be found in Javascript ."

If you use scripts in Asp.net, remember to note the difference.

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.