語言

ScriptManager.RegisterClientScriptResource 方法

定義

將嵌入組件中的用戶端腳本註冊, ScriptManager 並以控制項使用參與部分頁面渲染的控制項。

多載

名稱 Description
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

一個資源的識別碼。

例外狀況

用戶端資源 type 為 null。

-或-

負責註冊腳本的頁面是 null。

備註

當你用這種方法註冊腳本檔時,每次發生非同步回傳時,腳本都會被渲染出來。 若要註冊一個控制項內 UpdatePanel 的腳本,使該腳本僅在控制項更新時 UpdatePanel 註冊,請使用此 RegisterClientScriptResource(Control, Type, String) 方法的超載。

如果你想註冊一個不涉及部分頁面更新的腳本區塊,且只在初始頁面渲染時註冊一次腳本區塊,請使用 RegisterClientScriptBlock 該 ClientScriptManager 類別的方法。 你可以從ClientScriptManager頁面的屬性取得物件ClientScript的參考。

另請參閱

適用於

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

一個資源的識別碼。

例外狀況

用戶端資源 type 為 null。

-或-

負責註冊腳本的控制項為 null。

負責登錄腳本的控制項不在頁面的控制樹中。

備註

你用這個 RegisterClientScriptResource 方法註冊一個與部分頁面渲染相容且沒有 Microsoft Ajax 函式庫依賴的腳本。 使用此方法註冊的腳本資源,僅在 control 代表該控制項內且該控制項被更新時 UpdatePanel 才會註冊。 每次非同步回傳發生時都要註冊腳本,請使用此方法的 RegisterStartupScript(Page, Type, String, String, Boolean) 超載功能。

如果你想註冊一個不涉及部分頁面更新的腳本區塊,且只在初始頁面渲染時註冊一次腳本區塊,請使用 RegisterClientScriptBlock 該 ClientScriptManager 類別的方法。 你可以從ClientScriptManager頁面的屬性取得物件ClientScript的參考。

當從組件中存取資源時,會 RegisterClientScriptResource 使用此方法。 此方法將資源網址的內容納入元素 script 中。

這兩個RegisterClientScriptInclude方法都會RegisterClientScriptResource將腳本檔案載入瀏覽器。 如果已經載入了具有相同類型與鍵(腳本檔案)或相同類型與資源名稱(嵌入資源)的腳本,則該腳本不會被重新載入。

另請參閱

適用於