我試了一下,試了一下,在Google上看了一下,並沒有找到如何去做。我只是嘗試編寫一個簡單的用戶控件(.ascx)來顯示不同類型的廣告(所有這些廣告都是腳本)。問題是通常它是一個複雜的腳本,所以有人(這裏)建議將腳本保存爲.JS文件並從控件(.ascx)文件中調用它們。問題:我該怎麼做?嘗試了很多時間,這是不行的。我很沮喪... 任何人都可以請給我一個示例代碼如何做到這一點?如何在.ASCX文件中顯示.js文件/ Java腳本塊?
非常感謝!
public void Page_Load(Object sender, EventArgs e)
{
// Define the name, type and url of the client script on the page.
String csname = "ButtonClickScript";
String csurl = "~/script_include.js";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the include script exists already.
if (!cs.IsClientScriptIncludeRegistered(cstype, csname))
{
cs.RegisterClientScriptInclude(cstype, csname, ResolveClientUrl(csurl));
}
}
採取了這種方式,你有正確的URL腳本文件:
試過什麼?發佈你的「嘗試」 – Ian