Enhancement and Improvement of client script in ASP. NET 2.0 Reading Notes Temple

Source: Internet
Author: User
1. Set focus of the control
Controls that can set focus are as follows:
Button, checkbox, dropdownlist, hyperlink, imagebutton, linkbutton, ListBox, radiobutton, textbox
Four methods:
Page. setfocus (txtuserid );
This. setfocus (txtuserid );
Page. setfocus (txtuserid. clientid );
Txtuserid. Focus ();
-- Set the focus to page-level. JS: webform_autofocus ("txtuserid") is automatically generated. This webform_autofocus method is provided by IE.

2. Set webform form default button
This action is form-level.
<Form ID = "XX" defaultbutton = "btnsubmit" defaultfocus = "txtid" runat = "server">

3. client-side Click Event: onclientclick
Before initiating a server-side Click Event, run the onclientclick event on the client. This is a JS:
<Asp: button id = "btnclientclick" runat = "server"
Onclientclick = "Return confirm ('Are you sure you want to send? ')"
Onclick = "btnclientclick_click"/>

4. The dynamic registration of client-side JS does not have to be written to HTML:
The four methods have their own usage:
Registerclientscriptinclude("JS Registration Name", "JS relative path ")
Import an external JS File
Registerclientscriptblock(This. GetType (), "JS Registration Name", "JS Code", true)
InProgramIn hard coding, get a piece of JS and execute it.
Registerstartupscript(This. GetType (), "JS Registration Name", "JS Code ")
Only when form_load occurs, refreshing the page will trigger JS events again.
Registeronsubmitstatement
Triggered before submit, giving us the opportunity to cancel this operation before submission.

At the same time, before executing these methods, you must first check whether any JS with the same name is registered. Each check must be prefixed with "is" and "register" (for example, "registerclientscriptinclude" corresponds to "isclientscriptincluderegister ), parameter: (this. getType (), "JS Registration Name ")

4. asynchronous callback mechanism on the client side
Honestly, I didn't understand this section. Let me think about it again.

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.