LiteralControl 建構函式

定義

初始化 LiteralControl 類別的新執行個體。

多載

LiteralControl()

初始化 LiteralControl 類別的新執行個體,其包含要呈現在要求的 ASP.NET 網頁上的常值字串。

LiteralControl(String)

使用指定的文字,初始化 LiteralControl 類別的新執行個體。

LiteralControl()

初始化 LiteralControl 類別的新執行個體,其包含要呈現在要求的 ASP.NET 網頁上的常值字串。

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

範例

下列程式碼範例會建立可擴充 類別的 LiteralControl 類別 CustLiteralControlClass 。 它會使用未指定 物件文字的建構函式,建立名為 myLiteralControlClass1LiteralControl 類別實例。 建立物件之後, Text 會使用 屬性來設定它所包含的文字。

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

適用於

LiteralControl(String)

使用指定的文字,初始化 LiteralControl 類別的新執行個體。

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)

參數

text
String

要呈現在要求的 Web 網頁上的文字。

範例

下列程式碼範例會使用 LiteralControl 建構函式建立 類別的 LiteralControl 兩個實例。 這兩個實例會轉譯 H3 HTML 元素的開頭和結束記號,並包含要顯示在 H3 標籤內的文字。

// 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

另請參閱

適用於