ClientScriptManager.RegisterExpandoAttribute 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將名稱/值組註冊為指定之控制項的自訂 (Expando) 屬性。
多載
RegisterExpandoAttribute(String, String, String) |
使用控制項 ID、屬性名稱和屬性值,將名稱/值組註冊為指定之控制項的自訂 (Expando) 屬性。 |
RegisterExpandoAttribute(String, String, String, Boolean) |
使用控制項 ID、屬性名稱、屬性值,以及表示是否編碼屬性值的布林值,將名稱/值組註冊為指定之控制項的自訂 (Expando) 屬性。 |
RegisterExpandoAttribute(String, String, String)
使用控制項 ID、屬性名稱和屬性值,將名稱/值組註冊為指定之控制項的自訂 (Expando) 屬性。
public:
void RegisterExpandoAttribute(System::String ^ controlId, System::String ^ attributeName, System::String ^ attributeValue);
public void RegisterExpandoAttribute (string controlId, string attributeName, string attributeValue);
member this.RegisterExpandoAttribute : string * string * string -> unit
Public Sub RegisterExpandoAttribute (controlId As String, attributeName As String, attributeValue As String)
參數
- attributeName
- String
要註冊的自訂屬性名稱。
- attributeValue
- String
自訂屬性的值。
備註
方法 RegisterExpandoAttribute 會將名稱/值組註冊為指定 Control 上的自訂 (expando) 屬性。 expando 屬性會從 JavaScript 動態設定,以保留轉譯控制項標記的 XHTML 相容性。 自訂 (expando) 屬性值中的引號和反斜線會逸出。 如果您不想逸出引號和反斜線,請呼叫 RegisterExpandoAttribute 多載方法,並將 參數設定 encode
為 false
。
如果找不到 expando 屬性,或找不到要加入 expando 屬性的控制項,用戶端腳本仍會發出,但不會影響控制項。
另請參閱
適用於
RegisterExpandoAttribute(String, String, String, Boolean)
使用控制項 ID、屬性名稱、屬性值,以及表示是否編碼屬性值的布林值,將名稱/值組註冊為指定之控制項的自訂 (Expando) 屬性。
public:
void RegisterExpandoAttribute(System::String ^ controlId, System::String ^ attributeName, System::String ^ attributeValue, bool encode);
public void RegisterExpandoAttribute (string controlId, string attributeName, string attributeValue, bool encode);
member this.RegisterExpandoAttribute : string * string * string * bool -> unit
Public Sub RegisterExpandoAttribute (controlId As String, attributeName As String, attributeValue As String, encode As Boolean)
參數
- attributeName
- String
要註冊的自訂屬性名稱。
- attributeValue
- String
自訂屬性的值。
- encode
- Boolean
表示是否對要註冊之自訂屬性進行編碼的布林值。
範例
下列程式碼範例示範如何使用 RegisterExpandoAttribute 類別的 ClientScriptManager 方法。 轉譯頁面中的用戶端腳本會設定 title
專案的 屬性 <span>
。
<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public void Page_Load(Object sender, EventArgs e)
{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Register an expando attribute.
cs.RegisterExpandoAttribute("Message", "title", "New title from client script.", true);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ClientScriptManager Example</title>
</head>
<body>
<form id="Form1"
runat="server">
<span id="Message"
title="Title to be replaced.">
Place your mouse over this text to see the title.
</span>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Get a ClientScriptManager reference from the Page class.
Dim cs As ClientScriptManager = Page.ClientScript
' Register an expando attribute.
cs.RegisterExpandoAttribute("Message", "title", "New title from client script.", True)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ClientScriptManager Example</title>
</head>
<body>
<form id="Form1"
runat="server">
<span id="Message"
title="Title to be replaced.">
Place your mouse over this text to see the title.
</span>
</form>
</body>
</html>
備註
方法 RegisterExpandoAttribute 會將名稱/值組註冊為指定 Control 上的自訂 (expando) 屬性。 expando 屬性會從 JavaScript 動態設定,以保留轉譯控制項標記的 XHTML 相容性。 encode
如果您需要逸出 expando 屬性值中的引號和反斜線,請將 參數 true
設定為 。
如果找不到 expando 屬性,或找不到要加入 expando 屬性的控制項,用戶端腳本仍會發出,但不會影響控制項。