Editar

Compartir a través de


ClientScriptManager.RegisterExpandoAttribute Method

Definition

Registers a name/value pair as a custom (expando) attribute of the specified control.

Overloads

RegisterExpandoAttribute(String, String, String)

Registers a name/value pair as a custom (expando) attribute of the specified control given a control ID, attribute name, and attribute value.

RegisterExpandoAttribute(String, String, String, Boolean)

Registers a name/value pair as a custom (expando) attribute of the specified control given a control ID, an attribute name, an attribute value, and a Boolean value indicating whether to encode the attribute value.

RegisterExpandoAttribute(String, String, String)

Registers a name/value pair as a custom (expando) attribute of the specified control given a control ID, attribute name, and attribute value.

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)

Parameters

controlId
String

The Control on the page that contains the custom attribute.

attributeName
String

The name of the custom attribute to register.

attributeValue
String

The value of the custom attribute.

Remarks

The RegisterExpandoAttribute method registers a name/value pair as a custom (expando) attribute on the specified Control. The expando attribute is set dynamically from JavaScript to preserve XHTML compatibility for the rendered control's markup. Quotes and backslashes in the custom (expando) attribute's values are escaped. If you do not want to escape quotes and backslashes, call the RegisterExpandoAttribute overload method and set the encode parameter to false.

If the expando attribute is not found or the control to add the expando attribute to is not found, the client script is still emitted, but it will not affect the control.

See also

Applies to

RegisterExpandoAttribute(String, String, String, Boolean)

Registers a name/value pair as a custom (expando) attribute of the specified control given a control ID, an attribute name, an attribute value, and a Boolean value indicating whether to encode the attribute value.

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)

Parameters

controlId
String

The Control on the page that contains the custom attribute.

attributeName
String

The name of the custom attribute to register.

attributeValue
String

The value of the custom attribute.

encode
Boolean

A Boolean value indicating whether to encode the custom attribute to register.

Examples

The following code example demonstrates how to use the RegisterExpandoAttribute method of the ClientScriptManager class. The client script in the rendered page sets the title attribute of a <span> element.

<%@ 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>

Remarks

The RegisterExpandoAttribute method registers a name/value pair as a custom (expando) attribute on the specified Control. The expando attribute is set dynamically from JavaScript to preserve XHTML compatibility for the rendered control's markup. Set the encode parameter to true if you need to escape quotes and backslashes in your expando attribute's value.

If the expando attribute is not found or the control to add the expando attribute to is not found, the client script is still emitted, but it will not affect the control.

See also

Applies to