我只会在每一页的<head></head>里加一个js文件,好落后

解决方案 »

  1.   

    there are a few ways, for example, create your own page class, and override its Render method to write out "<script src='..'></script>", then derive your page class from this class, here is a similar example:ASP.NET Page Templates - Using Inheritance
    http://www.codeproject.com/aspnet/page_templates.aspor you can override the relevant methods in global.asax to output the javascript code block
      

  2.   

    哇,sauscer的信息全部搞定了,我详细写一下如何改写global.asax吧.
    3).使用资源文件
    NGWS基类支持,运行时有个类叫ResourceManager的实例可以使用。可以用ResourceWriter或者实用
    工具resgen.exe来生成资源文件,resgen以 key = value 的形式作为输入,如:
    ;
    ;注释
    ;
    [Strings]
    greetings = 欢迎你!
    more = 更多新闻资源文件的后缀为.resources。如何在页面中使用资源文件?
    用户的Content-Language可以用Request.UserLanguages[0]来取得。
    如何实现多语言支持?
    a).准备资源文件,生成.resources文件,文件取名规则:中间带Culture名。例:articles.en-us.resources
    b).global.asax中取得一个ResourceManager,并放如Application中供整个Application使用
    c).global.asax中为Application_BeginRequest事件写代码,根据客户的情况决定当前的Culture.
    d).在页面中用ResourceManager.GetString取得内容。例:
    //global.asax中:
    void Application_OnStart(){
    Application["RM"]=new ResourceManager("articles",Server.Mappath("resources"+Enviroment.DirectorySeparatorChar,null);
    }
    void Application_BeginRequest(Object sender,EventArgs e){
    try {
    Thread.CurrentThread.CurrentCulture = new
    CultureInfo(Request.UserLanguages[0]);
    }catch(ArgumentException){
    Thread.CurrentThread.CurrentCulture=new CultureInfo("en-us";
    }
    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
    }//default.asax中:
    ResourceManager rm;
    void Page_Init(Object sender,EventArgs e){
    rm=(ResouceManager)Application["RM"];
    }//输出内容时:
    <%= rm.GetString("greetings" %>将你的JAVAScript语句作为一个资源,在任何使用它的地方调用一句就可以了。