代码之家  ›  专栏  ›  技术社区  ›  Mohammad Dayyan

在ServerControl(ASP.NET)的<Head…/>标记中添加<Script…/>标记?

  •  2
  • Mohammad Dayyan  · 技术社区  · 14 年前

    我将在我的自定义服务器控件中使用JQuery文件,因此必须在Head标记中添加下面的行。

    <script type="text/javascript" src="jquery-1.4.3.min.js"></script>
    

    如何在服务器控件中使用C#

    1 回复  |  直到 14 年前
        1
  •  11
  •   Strelok    14 年前

    您可以使用 ClientScriptManager.RegisterClientScriptInclude Method 在页面加载期间。或者,您可以将脚本包含在.aspx页面中。如果这是公共服务器控件,则第一种方法可能更可取。

    编辑:也可以在 <head> 页面标签如下:

    HtmlGenericControl jqueryInclude = new HtmlGenericControl("script");
    jqueryInclude.Attributes.Add("type", "text/javascript");
    jqueryInclude.Attributes.Add("src", "http://<path to jQuery>");
    Page.Header.Controls.Add(jqueryInclude);