使用者控制項中引用JS或者CSS檔案

來源:互聯網
上載者:User

// 引入js檔案
            HtmlGenericControl scriptControl = new HtmlGenericControl("script");
            scriptControl.Attributes.Add("type", "text/javascript");
            scriptControl.Attributes.Add("language", "JavaScript");
            scriptControl.Attributes.Add("src", "../js/menu.js");
            Page.Header.Controls.Add(scriptControl);
// 引入樣式表
             Literal cssControl = new Literal();
            cssControl.Text = "<link href=\"../css/menu.css\" rel=\"stylesheet\" type=\"text/css\"/>";
            Page.Header.Controls.Add(cssControl);

引入js還可以利用:
if (!Page.ClientScript.IsClientScriptIncludeRegistered("menu"))
            Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "menu",
                Page.ResolveClientUrl(@"~/menu/menu.js"));

page類的東西蠻多的,呵呵~

 

本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/nailwl/archive/2009/06/30/4308832.aspx

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.