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 属性的控件未找到,则仍会发出客户端脚本,但不会影响控件。