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 。 呈现页面中的<span>
客户端脚本设置title
元素的属性。
<%@ 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 属性的控件,则仍会发出客户端脚本,但不会影响控件。