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.