ClientScriptManager.RegisterExpandoAttribute Método

Definición

Registra un par de nombre y valor como atributo personalizado (expando) del control especificado.

Sobrecargas

RegisterExpandoAttribute(String, String, String)

Registra un par de nombre y valor como atributo personalizado (expando) del control especificado incluyendo un Id. de control, nombre de atributo y valor de atributo.

RegisterExpandoAttribute(String, String, String, Boolean)

Registra un par de nombre y valor como atributo personalizado (expando) del control especificado proporcionando un Id. de control, un nombre de atributo, un valor de atributo y un valor booleano que indica si se codifica el valor de atributo.

RegisterExpandoAttribute(String, String, String)

Registra un par de nombre y valor como atributo personalizado (expando) del control especificado incluyendo un Id. de control, nombre de atributo y valor de atributo.

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)

Parámetros

controlId
String

Control Control en la página que contiene el atributo personalizado.

attributeName
String

Nombre del atributo personalizado que se va a registrar.

attributeValue
String

Valor del atributo personalizado.

Comentarios

El RegisterExpandoAttribute método registra un par nombre-valor como un atributo personalizado (expando) en el especificado Control. El atributo expando se establece dinámicamente desde JavaScript para conservar la compatibilidad XHTML para el marcado del control representado. Las comillas y barras diagonales inversas en los valores del atributo personalizado (expando) se aplican como escape. Si no desea escapar las comillas y barras diagonales inversas, llame al RegisterExpandoAttribute método de sobrecarga y establezca el encode parámetro en false.

Si no se encuentra el atributo expando o no se encuentra el control para agregar el atributo expando a , se sigue emitiendo el script de cliente, pero no afectará al control.

Consulte también

Se aplica a

RegisterExpandoAttribute(String, String, String, Boolean)

Registra un par de nombre y valor como atributo personalizado (expando) del control especificado proporcionando un Id. de control, un nombre de atributo, un valor de atributo y un valor booleano que indica si se codifica el valor de atributo.

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)

Parámetros

controlId
String

Control Control en la página que contiene el atributo personalizado.

attributeName
String

Nombre del atributo personalizado que se va a registrar.

attributeValue
String

Valor del atributo personalizado.

encode
Boolean

Valor booleano que indica si se codifica el atributo personalizado que se va a registrar.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el RegisterExpandoAttribute método de la ClientScriptManager clase . El script de cliente de la página representada establece el title atributo de un <span> elemento .

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

Comentarios

El RegisterExpandoAttribute método registra un par nombre-valor como un atributo personalizado (expando) en el especificado Control. El atributo expando se establece dinámicamente desde JavaScript para conservar la compatibilidad XHTML para el marcado del control representado. Establezca el encode parámetro true en si necesita escapar comillas y barras diagonales inversas en el valor del atributo expando.

Si no se encuentra el atributo expando o no se encuentra el control para agregar el atributo expando a , se sigue emitiendo el script de cliente, pero no afectará al control.

Consulte también

Se aplica a