Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DataBoundLiteralControl Class

Creates a control for HTML text to allow the handling of <%# %> data-binding expressions that are processed by the server. It persists the value of its Text property to view state. This class cannot be inherited.

For a list of all members of this type, see DataBoundLiteralControl Members.

System.Object
   System.Web.UI.Control
      System.Web.UI.DataBoundLiteralControl

[Visual Basic]
NotInheritable Public Class DataBoundLiteralControl
   Inherits Control
[C#]
public sealed class DataBoundLiteralControl : Control
[C++]
public __gc __sealed class DataBoundLiteralControl : public Control
[JScript]
public class DataBoundLiteralControl extends Control

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

This class allows the <%# ... %> data binding syntax to be implemented.

Example

[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);
      }
   }
};

[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

Namespace: System.Web.UI

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

Assembly: System.Web (in System.Web.dll)

See Also

DataBoundLiteralControl Members | System.Web.UI Namespace

Show:
© 2015 Microsoft