ScriptManager.RegisterClientScriptResource 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用 ScriptManager 控制項註冊內嵌在組件中的用戶端指令碼,以配合參與局部網頁呈現的控制項一起使用。
多載
RegisterClientScriptResource(Page, Type, String) |
每次發生回傳時,使用 ScriptManager 控制項註冊內嵌在組件中的用戶端指令碼檔。 |
RegisterClientScriptResource(Control, Type, String) |
使用 ScriptManager 控制項註冊內嵌在組件中的用戶端指令碼,以配合參與局部網頁呈現的控制項一起使用。 |
RegisterClientScriptResource(Page, Type, String)
每次發生回傳時,使用 ScriptManager 控制項註冊內嵌在組件中的用戶端指令碼檔。
public:
static void RegisterClientScriptResource(System::Web::UI::Page ^ page, Type ^ type, System::String ^ resourceName);
public static void RegisterClientScriptResource (System.Web.UI.Page page, Type type, string resourceName);
static member RegisterClientScriptResource : System.Web.UI.Page * Type * string -> unit
Public Shared Sub RegisterClientScriptResource (page As Page, type As Type, resourceName As String)
參數
- page
- Page
要註冊指令碼的頁面物件。
- type
- Type
用戶端指令碼的類型。 此參數通常會透過 typeof 運算子 (C#) 或 GetType 運算子 (Visual Basic) 指定,用以擷取註冊指令碼的控制項類型。
- resourceName
- String
資源的識別項。
例外狀況
備註
當您使用這個方法註冊腳本檔案時,每次發生非同步回傳時,就會轉譯腳本。 若要為控制項內的 UpdatePanel 控制項註冊腳本,以便只在更新控制項時 UpdatePanel 註冊腳本,請使用 RegisterClientScriptResource(Control, Type, String) 這個方法的多載。
如果您想要註冊與部分頁面更新無關的腳本區塊,而且如果您想要在初始頁面轉譯期間只註冊腳本區塊一次,請使用 RegisterClientScriptBlock 類別的 ClientScriptManager 方法。 您可以從頁面的 屬性取得 物件的 ClientScript 參考 ClientScriptManager 。
另請參閱
適用於
RegisterClientScriptResource(Control, Type, String)
使用 ScriptManager 控制項註冊內嵌在組件中的用戶端指令碼,以配合參與局部網頁呈現的控制項一起使用。
public:
static void RegisterClientScriptResource(System::Web::UI::Control ^ control, Type ^ type, System::String ^ resourceName);
public static void RegisterClientScriptResource (System.Web.UI.Control control, Type type, string resourceName);
static member RegisterClientScriptResource : System.Web.UI.Control * Type * string -> unit
Public Shared Sub RegisterClientScriptResource (control As Control, type As Type, resourceName As String)
參數
- control
- Control
要註冊指令碼的控制項。
- type
- Type
用戶端指令碼的類型。 此參數通常會透過 typeof 運算子 (C#) 或 GetType 運算子 (Visual Basic) 指定,用以擷取註冊指令碼的控制項類型。
- resourceName
- String
資源的識別項。
例外狀況
正在註冊指令碼的控制項不在網頁的控制項樹狀結構中。
備註
您可以使用 RegisterClientScriptResource 方法來註冊與部分頁面轉譯相容的腳本,而且沒有 Microsoft Ajax Library 相依性。 只有在代表已更新之 UpdatePanel 控制項內的控制項時 control
,才會註冊使用這個方法註冊的腳本資源。 若要在每次發生非同步回傳時註冊腳本,請使用 RegisterStartupScript(Page, Type, String, String, Boolean) 此方法的多載。
如果您想要註冊與部分頁面更新無關的腳本區塊,而且如果您想要在初始頁面轉譯期間只註冊腳本區塊一次,請使用 RegisterClientScriptBlock 類別的 ClientScriptManager 方法。 您可以從頁面的 屬性取得 物件的 ClientScript 參考 ClientScriptManager 。
透過 HTTP 處理常式存取來自元件的資源時,會 RegisterClientScriptResource 使用 方法。 這個方法包含 元素中 script
資源 URL 的內容。
RegisterClientScriptInclude和 方法都會 RegisterClientScriptResource 將腳本檔案載入瀏覽器中。 如果腳本檔案的相同類型和索引鍵 () ,或已載入內嵌資源) 的相同類型和資源名稱 (,則不會重載腳本。