1
一個小問題,我希望承認一個簡單的答案,我會踢自己不注意。當調用ScriptManager.RegisterStartupScript時,'Type'參數的意義是什麼?
所以,當我們的RegisterStartupScript
public static void RegisterStartupScript(
Control control,
Type type,
string key,
string script,
bool addScriptTags
)
以下過載,我們必須提供一個類型以及一個控制。現在,我可以看到指定控件的意義 - 只要控件是部分頁面呈現的一部分,腳本就會被推出。但是Type參數的意義是什麼?通常只是將其設置爲控件的類型。這實際上是MSDN提出的建議:
control
Type: System.Web.UI..::.Control
The control that is registering the client script block.
type
Type: System..::.Type
The type of the client script block. This parameter is usually specified by using the typeof operator (C#) or the GetType operator (Visual Basic) to retrieve the type of the control that is registering the script.
那麼爲什麼我們必須指定它呢?大概不僅僅是爲了讓.Net框架免費檢索運行時類型本身。
哦,所以控件本身不是唯一標識腳本的部分內容?因爲您可能有一個與特定類型的控件相關的類似腳本。好的我知道了。很酷,謝謝。 – Yellowfog 2010-07-21 15:53:32