Tina's blog
开心过好每一天! Come on !

//注册客户端id  

 public void RegisterClientId(params Control[] ctrls)
    {
        foreach (Control ctrl in ctrls)
        {
            string jscmd = "var {0} = document.getElementById(\"{1}\");\n";
            jscmd = string.Format(jscmd, ctrl.ID, ctrl.ClientID);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "JSClientId_" + ctrl.ID, jscmd, true);
        }
    }

//使用: RegisterClientId(this.btnAddLocationShowHid, this.trAddLocation, this.ddlLocationType,this.lnkBtnSearchLocation, this.hidTxt, this.txtLocationName);

 

//js,把所有js写道一个.js文件中

//通过下面的方法,把js文件加载到页面中去

    public void AppendJsLib(params string[] jsfiles)
    {
        Literal lit = new Literal();
        StringBuilder sb = new StringBuilder("\n");
        foreach (string jsfile in jsfiles)
        {
            sb.Append("<script type=\"text/javascript\" language=\"javascript\" src=\"" + GetStartUpPath() + "" + jsfile + "\"></script>\n");
        }
        lit.Text = sb.ToString();
        this.Page.Header.Controls.Add(lit);
    }

posted on 2008-07-30 15:29  Tinachang  阅读(237)  评论(0编辑  收藏  举报