ClientScriptManager.RegisterExpandoAttribute 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將名稱/值對註冊為指定控制項的自訂(展開)屬性。
多載
| 名稱 | Description |
|---|---|
| RegisterExpandoAttribute(String, String, String) |
根據控制 ID、屬性名稱及屬性值,註冊名稱/值對作為指定控制的自訂(展開)屬性。 |
| RegisterExpandoAttribute(String, String, String, Boolean) |
在指定控制項 ID、屬性名稱、屬性值及布林值(指示是否編碼該屬性值)時,將名稱/值對註冊為指定控制項的自訂(展開)屬性。 |
RegisterExpandoAttribute(String, String, String)
根據控制 ID、屬性名稱及屬性值,註冊名稱/值對作為指定控制的自訂(展開)屬性。
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 屬性是從 JavaScript 動態設定的,以保留渲染控制項標記的 XHTML 相容性。 自訂(expando)屬性中的引號和反斜線會被跳脫。 如果你不想跳脫引號和反斜線,請呼叫 RegisterExpandoAttribute overload 方法並將參數設 encode 為 false。
如果找不到 expando 屬性,或找不到將 expando 屬性加入的控制項,用戶端腳本仍會被執行,但不會影響控制項。
另請參閱
適用於
RegisterExpandoAttribute(String, String, String, Boolean)
在指定控制項 ID、屬性名稱、屬性值及布林值(指示是否編碼該屬性值)時,將名稱/值對註冊為指定控制項的自訂(展開)屬性。
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 屬性是從 JavaScript 動態設定的,以保留渲染控制項標記的 XHTML 相容性。 設定 encode 參數為 true :如果你需要在 expando 屬性的值中跳出引號和反斜線。
如果找不到 expando 屬性,或找不到將 expando 屬性加入的控制項,用戶端腳本仍會被執行,但不會影響控制項。