我創建了一個ASP.Net服務器控件,可以將其稱爲「WebGrid」。 WebGrid控件具有一個嵌入式JavaScript資源,該資源向任何承載它的頁面的ScriptManager註冊。在動態添加的服務器控件上註冊javascript資源
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
ClientScriptManager scriptManager = this.Page.ClientScript;
scriptManager.RegisterClientScriptResource(typeof(WebGrid), "Atl.Core.Resources.Scripts.WebGrid.js");
}
我也確信,在WebGrid.js文件被更改的文件的生成操作屬性嵌入的資源爲「嵌入的資源」,並增加資源,以項目的AssemblyInfo.cs這樣:
[assembly: WebResource("Atl.Core.Resources.Scripts.WebGrid.js", "text/js")]
現在,當控制在JavaScript資源使用ScriptManager註冊的aspx頁面的標記聲明,一切工作正常。但是,如果我通過一個按鈕動態地將控件添加到頁面的ControlCollection中,則單擊javascript不會被註冊,並且控件抱怨找不到這樣和那樣的javascript函數。請注意這兩個按鈕,分別位於不同的UpdatePanel中的WebGrid ...
編輯:看起來這個問題是因爲我使用的ClientScript與ScriptManager的看到(Differences between ScriptManager and ClientScript when used to execute JS?)。那麼,我該如何使用Page的ScriptManager註冊WebGrid的腳本?