This documentation is archived and is not being maintained.

DataBoundLiteralControl.Text Property

Gets the text content of the DataBoundLiteralControl object. This is a read-only property.

[Visual Basic]
Public ReadOnly Property Text As String
[C#]
public string Text {get;}
[C++]
public: __property String* get_Text();
[JScript]
public function get Text() : String;

Property Value

A System.String that represents the text content of the DataBoundLiteralControl object.

Example

[Visual Basic, C#, C++] The following example creates a user control that takes the text of the DataBoundLiteralControl object and displays it on the Web page. The following is the command line used to build the executable.

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

[Visual Basic] 
Imports System
Imports System.Web
Imports System.Web.UI


Namespace MyUserControl 
   
   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

[C#] 

using System;
using System.Web;
using System.Web.UI;

namespace MyUserControl 
{

   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>");

      }
    }
   }    
}


[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Web.dll>
using namespace System;
using namespace System::Web;
using namespace System::Web::UI;

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

[Visual Basic, C#, C++] The following example uses the previous custom control. Notice, the values shown in the Register directive reflect the previous command line.

[Visual Basic] 
<%@ Register TagPrefix="MyControlSample" Namespace="MyUserControl" Assembly="vb_myDataBoundLiteralControl" %>
<html>
 <head>
 <script language="VB" runat="server">
 Sub Page_Load(Sender As Object, 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>
[C#] 
<%@ Register TagPrefix="MyControlSample" Namespace="MyUserControl" Assembly="cs_myDataBoundLiteralControl" %>
<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>

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

DataBoundLiteralControl Class | DataBoundLiteralControl Members | System.Web.UI Namespace

Show: