Freigeben über


HtmlTextArea.Name-Eigenschaft

Ruft den eindeutigen Bezeichnernamen für das HtmlTextArea-Steuerelement ab oder legt diesen fest.

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)

Syntax

'Declaration
Public Overridable Property Name As String
'Usage
Dim instance As HtmlTextArea
Dim value As String

value = instance.Name

instance.Name = value
public virtual string Name { get; set; }
public:
virtual property String^ Name {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_Name ()

/** @property */
public void set_Name (String value)
public function get Name () : String

public function set Name (value : String)

Eigenschaftenwert

Eine Zeichenfolge, die den Wert der Control.UniqueID-Eigenschaft darstellt.

Hinweise

Mit der Name-Eigenschaft können Sie den eindeutigen Bezeichnernamen für das HtmlTextArea-Steuerelement bestimmen. In dieser Implementierung der Eigenschaft gibt der get-Accessor den Wert der Control.UniqueID-Eigenschaft zurück. Der set-Accessor weist dieser Eigenschaft jedoch keinen Wert zu.

Hinweis

Der set-Accessor weist dieser Eigenschaft keinen Wert zu, da die Name-Eigenschaft denselben Wert wie die Control.UniqueID-Eigenschaft aufweisen muss, damit das HtmlTextArea-Steuerelement ordnungsgemäß funktioniert.

Klassen, die von der HtmlTextArea-Klasse erben, können diese Implementierung bei Bedarf überschreiben.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie mit der Name-Eigenschaft ein HtmlTextArea-Steuerelement auf einer Seite ausgewählt und seine Value-Eigenschaft festgelegt wird.

<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<script runat="server" >
  
  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' Bind a data source to the Repeater control. 
    Repeater1.DataSource = CreateRepeaterSource()
    Repeater1.DataBind()

  End Sub

  Sub Item_Bound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
 
    ' The ItemDataBound event is raised when data is bound to an
    ' item in the Repeater control. Items can include the Header,
    ' Footer, and so on. Use the following logic only if the item 
    ' being bound is an Item or AlternatingItem.
    If (e.Item.ItemType = ListItemType.Item) Or _
       (e.Item.ItemType = ListItemType.AlternatingItem) Then

      ' The runtime automatically generates a unique identifier
      ' for each control embedded in a list control, such as the
      ' Repeater control. The Name property of the HtmlTextArea 
      ' control contains this unique identifier and is commonly used to 
      ' identify a specific control.
            
      ' Retrieve the HtmlTextArea control from the RepeaterItem.
      Dim area As HtmlTextArea = _
          CType(e.Item.FindControl("TextArea1"), HtmlTextArea)

      ' Insert a custom message for the fourth HtmlTextArea control by
      ' looking for a Name property that contains the number 3.
      If area.Name.Contains("3") Then

        area.Value = "Hello World"

      End If

    End If

  End Sub

  Function CreateRepeaterSource() As DataView

    ' Create a DataTable that contains sample data for the 
    ' Repeater control.
    Dim dt As DataTable = New DataTable()
    Dim dr As DataRow
 
    dt.Columns.Add(New DataColumn("Category", GetType(String)))
 
    ' Populate the DataTable with sample values.
    Dim i As Integer
 
    For i = 0 To 4
       
      dr = dt.NewRow()
 
      dr(0) = "Category " & i.ToString()

      dt.Rows.Add(dr)
         
    Next i
 
    ' Create a DataView from the DataTable.
    Dim dv As DataView = New DataView(dt)
    Return dv

  End Function
  
</script>

<html>
<head>
   <title>HtmlTextArea Name Example</title>
</head>  
<body>

   <form runat="server">
  
      <h3>HtmlTextArea Name Example</h3>

      Notice that Category 3 has custom text. <br> 
  
      <asp:Repeater id="Repeater1"
                    onitemdatabound="Item_Bound"
                    runat="server">

         <ItemTemplate>

            <h4><%# DataBinder.Eval(Container.DataItem, "Category") %></h4>

            Enter text:

            <br>

            <textarea id="TextArea1" 
                      runat="server"/>

            <br><br>

            <hr>

         </ItemTemplate>

      </asp:Repeater>
  
   </form>

</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<script runat="server" >
  
  void Page_Load(Object sender, EventArgs e)
  {

    // Bind a data source to the Repeater control. 
    Repeater1.DataSource = CreateRepeaterSource();
    Repeater1.DataBind();

  }

  void Item_Bound(Object sender, RepeaterItemEventArgs e)
  {

    // The ItemDataBound event is raised when data is bound to an 
    // item in the Repeater control. Items can include the Header,
    // Footer, and so on. Use the following logic only if the item 
    // being bound is an Item or AlternatingItem.
    if (e.Item.ItemType == ListItemType.Item ||
        e.Item.ItemType == ListItemType.AlternatingItem)
    {

      // The runtime automatically generates a unique identifier 
      // for each control embedded in a list control, such as the
      // Repeater control. The Name property of the HtmlTextArea 
      // control contains this unique identifier and is commonly used to 
      // identify a specific control.

      // Retrieve the HtmlTextArea control from the RepeaterItem.
      HtmlTextArea area = (HtmlTextArea)e.Item.FindControl("TextArea1");

      // Insert a custom message for the fourth HtmlTextArea control by
      // looking for a Name property that contains the number 3.
      if (area.Name.Contains("3"))
      {

        area.Value = "Hello World";

      }

    }

  }

  DataView CreateRepeaterSource()
  {

    // Create a DataTable that contains sample data for the 
    // Repeater control.
    DataTable dt = new DataTable();
    DataRow dr;

    dt.Columns.Add(new DataColumn("Category", typeof(String)));

    // Populate the DataTable with sample values.
    for (int i = 0; i < 5; i++)
    {
      dr = dt.NewRow();

      dr[0] = "Category " + i.ToString();

      dt.Rows.Add(dr);
    }

    // Create a DataView from the DataTable.
    DataView dv = new DataView(dt);
    return dv;

  }
  
</script>

<html>
<head>
    <title>HtmlTextArea Name Example</title>
</head>
  
<body>

   <form runat="server">
  
      <h3>HtmlTextArea Name Example</h3>

      Notice that Category 3 has custom text. <br>  
  
      <asp:Repeater id="Repeater1"
                    onitemdatabound="Item_Bound"
                    runat="server">

         <ItemTemplate>

            <h4><%# DataBinder.Eval(Container.DataItem, "Category") %></h4>

            Enter text:

            <br>

            <textarea id="TextArea1" 
                      runat="server"/>

            <br><br>

            <hr>

         </ItemTemplate>

      </asp:Repeater>
  
   </form>

</body>
</html>
 

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

HtmlTextArea-Klasse
HtmlTextArea-Member
System.Web.UI.HtmlControls-Namespace
Control.UniqueID

Weitere Ressourcen

HTML-Serversteuerelemente