vs中的小技巧

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();");
    }
设置日期文本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);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值