1 防止前台加载的脚本执行的速度可以采用下面的方法: |
<script language="javascript" type="text/javascript"> var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_initializeRequest(initializeRequest); var postbackElement; function initializeRequest(sender, args) { if (prm.get_isInAsyncPostBack()) { args.set_cancel(true); CallFuncAfterAsyncPostBack(args.get_postBackElement().click); return; } } function CallFuncAfterAsyncPostBack(func) { if(prm.get_isInAsyncPostBack()) { window.setTimeout(function(){ CallFuncAfterAsyncPostBack(func); }, 100); return; } func(); } </script> |
2 弹出窗口 |
protected void ShowDialog(string PagePath, string width, string height) { string strScript = "var reload = window.showModalDialog('" + PagePath + "',window,'"; strScript += "dialogWidth:" + width + "px;"; strScript += "dialogHeight:" + height + "px;"; strScript += "help:no;status:no;scroll:no');"; strScript += "if (reload == 1) window.location.reload();"; ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "ShowDialog", strScript, true); } |
3 显示提示信息(关闭页面,刷新父页面) |
protected void ShowMessageClose(string msg, int reload) { string strScript = "alert('" + msg + "');"; strScript += "window.returnValue=" + reload + ";"; strScript += "window.opener=null;window.close();"; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ShowMessageClose", strScript, true); } |
4 设置Textbox的默认回车事件 |
protected void SetDefaultbutton(TextBox control, string buttonID) { control.Attributes.Add("onkeydown", "if(event.keyCode==13) document.all('" + buttonID + "').click();"); } |
5 设置日期文本Textbox控件的清除事件 |
protected void SetCalendarClear(TextBox control) { control.Attributes.Add("onmousedown", "this.value = '';"); } |
6 弹出窗口,并执行指定js函数 |
protected void ShowDialog(string PagePath, string width, string height, string funcName, string[] parms) { string strScript = "var reload = window.showModalDialog('" + PagePath + "',window,'"; strScript += "dialogWidth:" + width + "px;"; strScript += "dialogHeight:" + height + "px;"; strScript += "help:no;status:no;scroll:no');"; string parm = string.Empty; foreach (string str in parms) { parm += ",'" + str + "'"; } if (parm.Length > 0) { parm = parm.Substring(1); } strScript += "if (reload == 1) " + funcName + "(" + parm + ");"; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ShowDialog", strScript, true); } |