Freigeben über


DataBoundLiteralControl.Text-Eigenschaft

Ruft den Textinhalt des DataBoundLiteralControl-Objekts ab.

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

Syntax

'Declaration
Public ReadOnly Property Text As String
'Usage
Dim instance As DataBoundLiteralControl
Dim value As String

value = instance.Text
public string Text { get; }
public:
property String^ Text {
    String^ get ();
}
/** @property */
public String get_Text ()
public function get Text () : String

Eigenschaftenwert

Ein String, der den Textinhalt des DataBoundLiteralControl darstellt.

Hinweise

Die DataBoundLiteralControl-Klasse behält den Wert ihrer Text-Eigenschaft im Ansichtszustand bei.

Beispiel

Im folgenden Codebeispiel wird ein benutzerdefiniertes Steuerelement erstellt, mit dessen Hilfe aus einer ASPX-Datei der Text eines DataBoundLiteralControl-Objekts angezeigt wird. Das benutzerdefinierte Steuerelement ruft ein DataBoundLiteralControl-Objekt ab und gibt die Texteigenschaft in seiner Render-Methode aus.

Imports System
Imports System.Web
Imports System.Web.UI


Namespace Samples.AspNet.VB.Controls 
   
   Public Class MyControlVB
      Inherits Control     

      <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
      Protected Overrides Sub Render(Output As HtmlTextWriter)
         ' Checks if a DataBoundLiteralControl object is present.
         If HasControls() And TypeOf Controls(0) Is DataBoundLiteralControl Then            

            ' Obtains the DataBoundLiteralControl instance.
            Dim boundLiteralControl As DataBoundLiteralControl = CType(Controls(0), DataBoundLiteralControl)
            ' Retrieves the text in the boundLiteralControl object.
            Dim text As String = boundLiteralControl.Text
            output.Write(("<h4>Your Message: " + text + "</h4>"))
         End If 
      End Sub 'Render  

   End Class 'MyControl
End Namespace 'MyUserControl
using System;
using System.Web;
using System.Web.UI;

namespace Samples.AspNet.CS.Controls 
{

   public class MyControl : Control 
   {
 
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
    protected override void Render(HtmlTextWriter output) 
    {
      // Checks if a DataBoundLiteralControl object is present.
      if ( (HasControls()) && (Controls[0] is DataBoundLiteralControl) ) 
      {
        // Obtains the DataBoundLiteralControl instance.
        DataBoundLiteralControl boundLiteralControl = (DataBoundLiteralControl)Controls[0];
        // Retrieves the text in the boundLiteralControl object.
        String text = boundLiteralControl.Text;
        output.Write("<h4>Your Message: " +text+"</h4>");

      }
    }
   }    
}
/*File name: myDataBoundLiteralControl.jsl */
import System.*;
import System.Web.*;
import System.Web.UI.*;

public class MyControl extends Control
{
    protected void Render(HtmlTextWriter output)
    {
        // Checks if a DataBoundLiteralControl object is present.
        if (HasControls() && get_Controls().get_Item(0)
            instanceof DataBoundLiteralControl) {
            // Obtains the DataBoundLiteralControl instance.
            DataBoundLiteralControl boundLiteralControl =
                (DataBoundLiteralControl)get_Controls().get_Item(0);
            // Retrieves the text in the boundLiteralControl object.
            String text = boundLiteralControl.get_Text();
            output.Write("<h4>Your Message: " + text + "</h4>");
        }
    } //Render 
} //MyControl

Sie können das Steuerelement mit dem Visual Basic-Compiler (vbc.exe) oder C#-Compiler (csc.exe) kompilieren. Die erhaltene DLL-Datei muss im Verzeichnis Bin des Webprojekts platziert werden. Dies wird im folgenden Codebeispiel verschaulicht.

vbc /r:System.dll /r:System.Web.dll /t:library /out:myWebAppPath/bin/vb_myDataBoundLiteralControl.dll myDataBoundLiteralControl.vb
csc /t:library /out:myWebAppPath/bin/cs_myDataBoundLiteralControl.dll myDataBoundLiteralControl.cs

Im folgenden Codebeispiel wird veranschaulicht, wie das benutzerdefinierte Steuerelement in einer ASPX-Datei registriert und verwendet wird.

<%@ Page Language="VB" %>
<%@ Register TagPrefix="MyControlSample" Namespace="Samples.AspNet.VB.Controls" %>
<html>
  <head>
    <script language="VB" runat="server">
        Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)
            Page.DataBind()
        End Sub
    </script>
  </head>
  <body>
  <h3>
      DataBoundLiteralControl Example
  </h3>
  <form method="post" runat="server" ID="Form1">
    <asp:Label id="Label1" Text="This is a string retrieved from 'DataBoundLiteralControl'" Runat="server" Visible="False"></asp:Label>
    <MyControlSample:MyControlVB id="MyControl" runat="server">
        <%# Label1.Text %>
    </MyControlSample:MyControlVB>
  </form>
  </body>
</html>
<%@ Page Language="C#" %>
<%@ Register TagPrefix="MyControlSample" Namespace="Samples.AspNet.CS.Controls" %>
<html>
  <head>
    <script language="C#" runat="server">
      void Page_Load(Object Sender, EventArgs e)
      {
        Page.DataBind();
      }
    </script>
  </head>
  <body>
  <h3>
    DataBoundLiteralControl Example
  </h3>
  <form method="post" runat="server" ID="Form1">
    <asp:Label id="Label1" Text="This is a string retrieved from 'DataBoundLiteralControl'" Runat="server" Visible="False"></asp:Label>
    <MyControlSample:MyControl id="MyControl" runat="server">
        <%# Label1.Text %>
    </MyControlSample:MyControl>
  </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

DataBoundLiteralControl-Klasse
DataBoundLiteralControl-Member
System.Web.UI-Namespace