1. Button Front Background event
<asp:button id= "Button1" runat= "Server" onclick= "Button1_Click" text= "button"
onclientclick= "alert (' room-side verification, block submission to server-side '); return false;"/>
2. Registration Related events: Onblur,onclick,onchange
This. TEXTBOX1.ATTRIBUTES.ADD ("onchange",
"Alert (' The data is changed, now check whether the input conforms to the rules ');");
3. Register the relevant properties:
This. TEXTBOX1.ATTRIBUTES.ADD ("ReadOnly", "true");
4. Introduction of JS File
Foreground HTML page:
<script type= "Text/javascript" src= "Jscript.js" language= "JavaScript" ></script>
<script type= "Text/javascript" language= "JavaScript" >
function Fn_name ()
{
Alert ("JS");
}
</script>
Background CS Page:
This. RegisterClientScriptBlock ("Jsfile",
"<script type= ' text/javascript ' src= ' jscript.js ' language= ' JavaScript ' ></script>");
5. When the button is clicked, the relevant field is not empty.
function Checkempty (txtobj,msgshow)
{
if (Txtobj.value = = "")
{
alert (msgshow);
return false;
}
}
<asp:button id= "Button1" runat= "Server" onclick= "Button1_Click" text= "button"
onclientclick= "Return Checkempty (TextBox1, ' TextBox1 cannot be empty ')"/>
6. Whether or not the textbox corresponding to the Chcekbox can be entered by selecting the
function Chktextbox (chkobj,txtobj)
{
if (chkobj.checked==true)
{
Txtobj.value = "";
Txtobj.readonly = false;
Txtobj.focus ();
}
if (chkobj.checked = = False)
{
Txtobj.value = "";
Txtobj.readonly = true;
}
}
<input id= "Checkbox1" type= "checkbox" onclick= "Chktextbox (checkbox1,textbox1)"/>
7. Pass the value to the modal window and get the value returned
var encodequeryname = Escape (Name);
var Strpara = "' Dialogwidth:400px;dialogheight:400px;dialogleft:300px;dialogtop:200px;toolbar:no;menubar:no; Resizable:yes;location:no;status:no;scrollbars= no ' ";
var returninfo = window.showModalDialog ("qryname.aspx?&name=" +encodequeryname + "&queryid=" +QueryType+ "", " , Strpara);
if (Returninfo!=null)
{
var arrayreturninfo = returninfo. Split ("@");
Document.all.drpID.value = arrayreturninfo[1];
Document.all.txtname.value= arrayreturninfo[2];
}
8. Popup JS confirmation dialog, and trigger background related actions according to the confirmation result
if (Confirm (' Confirm how? '))
{
Document.all.hidbtn_Submit.click ();
}
Else
{
Document.all.hidbtn_Cancel.click ();
}
HTML page related code:
<input id= "Hidbtn_submit" type= "button" value= "Confirm modification"
Style= "Display:none;"
onserverclick= "Hidbtn_submit_serverclick"
runat= "Server"/>
9. Add a page response to an accelerator, such as a new button when pressing F2
#region Add a page response to a shortcut key
String Strjs_shortkey = "<script language= ' javascript ' type= ' text/javascript ' >";
Strjs_shortkey + = "document.onkeydown=shortkeydown;";
Strjs_shortkey + = "function Shortkeydown ()";
Strjs_shortkey + = "{";
New
if (this. ButtonCtl1.ImgBtn_AddFamily.Visible)
{
String btninsertcid = this. ButtonCtl1.ImgBtn_Insert.ClientID.Trim ();
f2-113
Strjs_shortkey + = "if (event.keycode== ' 113 ')";
Strjs_shortkey + = "{";
Strjs_shortkey + = "document.all ('" + Btninsertcid + "')." Click (); ";
Strjs_shortkey + = "event.keycode= 0;";
Strjs_shortkey + = "Event.returnvalue = false;";
Strjs_shortkey + = "return false;";
Strjs_shortkey + = "}";
}
Modify
if (this. ButtonCtl1.ImgBtn_Edit.Visible)
{
String btneditcid = this. ButtonCtl1.ImgBtn_Edit.ClientID.Trim ();
f3-114
Strjs_shortkey + = "if (event.keycode== ' 114 ')";
Strjs_shortkey + = "{";
Strjs_shortkey + = "document.all ('" + Btneditcid + "')." Click (); ";
Strjs_shortkey + = "event.keycode= 0;";
Strjs_shortkey + = "Event.returnvalue = false;";
Strjs_shortkey + = "return false;";
Strjs_shortkey + = "}";
}
Strjs_shortkey + = "}";
Registering events
Page.registerstartupscript ("Shortkey", Strjs_shortkey);
#endregion
10. Pop-up hints on the branch display
Alert (' AAA \ r \ n bbb \ r \ n CCC ');
If you are registering in the background. cs file
String stralertcontent = "AAA" + "\\r\\n";
Stralertcontent + = "BBB" + "\\r\\n";
11. When you click a row on the GridView, the RadioButton at the beginning of the column is selected, and the relevant values are saved in the hidden field
Bind with a queried dataset
if (dt. Rows.Count > 0)
{
Binding
This.gv_InfoFromSendModule.DataSource = DT;
This.gv_InfoFromSendModule.DataBind ();
OK button display
This.btn_ok. Visible = true;
This.txthid_RowCount.Text = dt. Rows.Count.ToString ();
}
The RowDataBound of the GridView
protected void Gv_infofromsendmodule_rowdatabound (object sender, GridViewRowEventArgs e)
{
if (E.row.rowindex < 0)
Return
E.row.attributes.add ("onclick", "Radbutton" + e.row.rowindex.tostring () + "', '" + e.row.cells[1]. Text.trim () + "');");
RadioButton rad = (RadioButton) e.row.cells[0]. FindControl ("Rad_select");
Rad. Attributes.Add ("onclick", "Radbutton" (' "+e.row.rowindex.tostring () +" ', ' "+ e.row.cells[1]. Text.trim () + "');");
}
The JS that is bound on the line
function Radbutton (ROWINDEX,ROWGUID)
{
Gv_infofromsendmodule$ctl02$rad_select
var rowCount = parseint (document.all.txthid_RowCount.value) +2;
for (Var i=2;i<rowcount;i++)
{
var tmpname;
if (i<10)
{
Tmpname = "Gv_infofromsendmodule$ctl0" +i+ "$rad _select";
}
Else
{
Tmpname = "Gv_infofromsendmodule$ctl" +i+ "$rad _select";
}
Get the corresponding Radio object
var Tmpradio = document.getElementById (tmpname);
Currently check other unchecked
if ((i-2) = = RowIndex)
{
Tmpradio.checked = true;
}
Else
{
tmpradio.checked = false;
}
}
Document.all.txthid_GUID.value = RowGUID;
}
12. Remove the front and back spaces
function Fn_trim (obj)
{
if (obj==null)
{
Return
}
Else
{
var oldstr = Obj.value;
var newstr = Oldstr.replace (/^\s+|\s+$/g, "");
Obj.value = Newstr;
}
}
13.TextBox text content length determine if more than the length exceeds the return true
function Fn_istoolong (obj,varlength)
{
if (obj==null)
{
return false;
}
Else
{
var valuestr = Obj.value;
var len = valuestr.match (/[^-~]/g) = = null? ValueStr.length:valueStr.length + valuestr.match (/[^-~]/g). length;
if (Len > parseint (varlength))
{
return true;
}
Else
{
return false;
}
}
}
Summarize the 13 JS script code commonly used in ASP.