ClientScriptManager.RegisterExpandoAttribute Metoda

Definicja

Rejestruje parę nazwa/wartość jako atrybut niestandardowy (expando) określonej kontrolki.

Przeciążenia

RegisterExpandoAttribute(String, String, String)

Rejestruje parę nazwa/wartość jako atrybut niestandardowy (expando) określonej kontrolki przy użyciu identyfikatora kontrolki, nazwy atrybutu i wartości atrybutu.

RegisterExpandoAttribute(String, String, String, Boolean)

Rejestruje parę nazwa/wartość jako atrybut niestandardowy (expando) określonej kontrolki przy użyciu identyfikatora kontrolki, nazwy atrybutu, wartości atrybutu i wartości logicznej wskazującej, czy zakodować wartość atrybutu.

RegisterExpandoAttribute(String, String, String)

Rejestruje parę nazwa/wartość jako atrybut niestandardowy (expando) określonej kontrolki przy użyciu identyfikatora kontrolki, nazwy atrybutu i wartości atrybutu.

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)

Parametry

controlId
String

Element Control na stronie zawierającej atrybut niestandardowy.

attributeName
String

Nazwa atrybutu niestandardowego do zarejestrowania.

attributeValue
String

Wartość atrybutu niestandardowego.

Uwagi

Metoda RegisterExpandoAttribute rejestruje parę nazwa/wartość jako atrybut niestandardowy (expando) w określonym Controlobiekcie . Atrybut expando jest ustawiany dynamicznie z języka JavaScript w celu zachowania zgodności XHTML na potrzeby adiustacji renderowanej kontrolki. Cudzysłowy i ukośniki odwrotne w wartościach atrybutu niestandardowego (expando) są ucieczką. Jeśli nie chcesz ucieczki cudzysłowów i ukośników odwrotnych, wywołaj metodę RegisterExpandoAttribute przeciążenia i ustaw encode parametr na false.

Jeśli atrybut expando nie zostanie znaleziony lub kontrolka, aby dodać atrybut expando do nie zostanie znaleziony, skrypt klienta jest nadal emitowany, ale nie wpłynie to na kontrolkę.

Zobacz też

Dotyczy

RegisterExpandoAttribute(String, String, String, Boolean)

Rejestruje parę nazwa/wartość jako atrybut niestandardowy (expando) określonej kontrolki przy użyciu identyfikatora kontrolki, nazwy atrybutu, wartości atrybutu i wartości logicznej wskazującej, czy zakodować wartość atrybutu.

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)

Parametry

controlId
String

Element Control na stronie zawierającej atrybut niestandardowy.

attributeName
String

Nazwa atrybutu niestandardowego do zarejestrowania.

attributeValue
String

Wartość atrybutu niestandardowego.

encode
Boolean

Wartość logiczna wskazująca, czy zakodować atrybut niestandardowy do zarejestrowania.

Przykłady

W poniższym przykładzie kodu pokazano, jak używać RegisterExpandoAttribute metody ClientScriptManager klasy . Skrypt klienta na renderowanej stronie ustawia title atrybut <span> elementu.

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

Uwagi

Metoda RegisterExpandoAttribute rejestruje parę nazwa/wartość jako atrybut niestandardowy (expando) w określonym Controlobiekcie . Atrybut expando jest ustawiany dynamicznie z języka JavaScript w celu zachowania zgodności XHTML na potrzeby adiustacji renderowanej kontrolki. encode Ustaw parametr na true wartość , jeśli chcesz uniknąć cudzysłowów i ukośników odwrotnych w wartości atrybutu expando.

Jeśli atrybut expando nie zostanie znaleziony lub kontrolka, aby dodać atrybut expando do nie zostanie znaleziony, skrypt klienta jest nadal emitowany, ale nie wpłynie to na kontrolkę.

Zobacz też

Dotyczy