我有一个js脚本文件,可是不知道怎么实现render.

解决方案 »

  1.   

    是不是在写自定义控件阿,可以覆盖OnPreRender方法实现添加js,比如:
    /// <summary>
    /// Add a JavaScript to the Page and call it from the onKeyPress event
    /// </summary>
    /// <param name="e"></param>
    override protected void OnPreRender(EventArgs e) 
    { if (this.Page.Request.Browser.JavaScript == true) 
    {
    // Build JavaScript
    StringBuilder s = new StringBuilder();
    s.Append("\n<script type='text/javascript' language='JavaScript'>\n");
    s.Append("<!--\n");
    s.Append("    function NumberBoxKeyPress(event, dp, dc, n) {\n");
    s.Append("      var myString = new String(event.srcElement.value);\n");
    s.Append("      var pntPos = myString.indexOf(String.fromCharCode(dc));\n");
    s.Append("      var keyChar = window.event.keyCode;\n");
    s.Append("       if ((keyChar < 48) || (keyChar > 57)) {\n");
    s.Append("          if (keyChar == dc) {\n");
    s.Append("              if ((pntPos != -1) || (dp < 1)) {\n");
    s.Append("                  return false;\n");
    s.Append("              }\n");
    s.Append("          } else \n");
    s.Append("if (((keyChar == 45) && (!n || myString.length != 0)) || (keyChar != 45)) \n");
    s.Append("      return false;\n");
    s.Append("       }\n");
    s.Append("       return true;\n");
    s.Append("    }\n");
    s.Append("// -->\n");
    s.Append("</script>\n");

    // Add the Script to the Page
    this.Page.RegisterClientScriptBlock("NumberBoxKeyPress", s.ToString()); // Add KeyPress Event
    try 
    {
    this.Attributes.Remove("onKeyPress");

    finally 
    {
    this.Attributes.Add("onKeyPress", "return NumberBoxKeyPress(event, " 
    + DecimalPlaces.ToString() + ", " 
    + ((int)DecimalSymbol).ToString() + ", " 
    + AllowNegatives.ToString().ToLower() + ")");
    }
    }
    }
      

  2.   

    我希望是单独的js在页面render.
      

  3.   

    1.1可以利用HtmlGenericControl script = new HtmlGenericControl("script");script.Attributes["src"] = “/yourscript.js";最后把空间加载到页面就可以。2.0就简单多了
    ClientScriptManager.RegisterClientScriptInclude 方法 (String, String) 
    可以直接实现。
      

  4.   

    http://singlepine.cnblogs.com/archive/2005/11/27/285648.html