当前位置:编程学习 > C#/ASP.NET >>

后台导入js文件



这个页面有母版页,,然后我要在后台再导入一个js文件

HtmlGenericControl scriptControl = new HtmlGenericControl("script");
            scriptControl.Attributes.Add("type", "text/javascript");
            scriptControl.Attributes.Add("language", "JavaScript");
            scriptControl.Attributes.Add("src", "js/province/zhejiang/hangzhou.js");
            Page.Header.Controls.Add(scriptControl);



这段代码在没有引用母版页的页面是可以成功的,但现在在有母版页的情况下就报错




请问这个问题怎么解决


js asp.net 后台导入 --------------------编程问答--------------------

protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(this.Page.GetType(), "jquery_min_1_8_3"))
            {
                this.Page.ClientScript.RegisterClientScriptInclude(this.Page.GetType(), "jquery_min_1_8_3", "../JavaScript/jquery-1.8.3.min.js");
            }
            if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(this.Page.GetType(), "uctrlDiaModal"))
            {
                this.Page.ClientScript.RegisterClientScriptInclude(this.Page.GetType(), "uctrlDiaModal", "../UserCtrl/uctrlDiaModal.js");
            }
        }

这样试下看行不
--------------------编程问答--------------------
引用 1 楼 blueskybcl 的回复:

protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(this.Page.GetType(), "jquery_min_1_8_3"))
            {
                this.Page.ClientScript.RegisterClientScriptInclude(this.Page.GetType(), "jquery_min_1_8_3", "../JavaScript/jquery-1.8.3.min.js");
            }
            if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(this.Page.GetType(), "uctrlDiaModal"))
            {
                this.Page.ClientScript.RegisterClientScriptInclude(this.Page.GetType(), "uctrlDiaModal", "../UserCtrl/uctrlDiaModal.js");
            }
        }

这样试下看行不






这个怎么用的 --------------------编程问答-------------------- 继续求啊,怎么解决啊,或者有什么方法可以动态加载js
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,