我需要能够为用户控件添加外部js文件(使用

    this.Page.ClientScript.RegisterClientScriptInclude("SuggestionSearch",
"~/Secure/Shared/SuggestionSearch.js");


句法)

但这将javascript文件放在页面上为时过早...是否有办法将文件放在页面底部?

最佳答案

看看ClientScriptManager.RegisterStartupScript

这样的事情可能会起作用:

ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "SuggestionSearch",
String.Format("<script src='{0}' type='text/javascript'></script>", ResolveUrl("~/Secure/Shared/SuggestionSearch.js")));

09-25 15:24