Επεξεργασία

Κοινή χρήση μέσω


LiteralControl Constructors

Definition

Initializes a new instance of the LiteralControl class.

Overloads

LiteralControl()

Initializes a new instance of the LiteralControl class that contains a literal string to be rendered on the requested ASP.NET page.

LiteralControl(String)

Initializes a new instance of the LiteralControl class with the specified text.

LiteralControl()

Initializes a new instance of the LiteralControl class that contains a literal string to be rendered on the requested ASP.NET page.

public:
 LiteralControl();
public LiteralControl ();
Public Sub New ()

Examples

The following code example creates a class, CustLiteralControlClass, that extends the LiteralControl class. It creates an instance of the class named myLiteralControlClass1 by using the constructor that does not specify the text of the LiteralControl object. After the object is created, the Text property is used to set the text that it contains.

CustomLiteralControlClass myLiteralControlClass1= 
               new CustomLiteralControlClass();
myLiteralControlClass1.Text="This Control demonstrates the constructor1";
Dim myLiteralControlClass1 as CustomLiteralControlClass = _
new CustomLiteralControlClass()
myLiteralControlClass1.Text="This Control demonstrates the constructor1"

Applies to

LiteralControl(String)

Initializes a new instance of the LiteralControl class with the specified text.

public:
 LiteralControl(System::String ^ text);
public LiteralControl (string text);
new System.Web.UI.LiteralControl : string -> System.Web.UI.LiteralControl
Public Sub New (text As String)

Parameters

text
String

The text to be rendered on the requested Web page.

Examples

The following code example creates two instances of the LiteralControl class using the LiteralControl constructor. The two instances render opening and closing tags for an H3 HTML element, and include the text to display within the H3 tags.

// Add two LiteralControls that render HTML H3 elements and text.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
protected override void CreateChildControls() {

    this.Controls.Add(new LiteralControl("<h3>Value: "));

    TextBox box = new TextBox();
    box.Text = "0";
    this.Controls.Add(box);

    this.Controls.Add(new LiteralControl("</h3>"));
}
' Add two LiteralControls that render HTML H3 elements and text.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub CreateChildControls()

    Me.Controls.Add(New LiteralControl("<h3>Value: "))

    Dim Box As New TextBox
    Box.Text = "0"
    Me.Controls.Add(box)

    Me.Controls.Add(New LiteralControl("</h3>"))
End Sub

See also

Applies to