This documentation is archived and is not being maintained.

Literal.AddParsedSubObject Method

This member overrides Control.AddParsedSubObject(Object), and more complete documentation might be available in that topic.

Notifies the Literal control that an XML or HTML element was parsed and adds that element to the ControlCollection of the control.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

Protected Overrides Sub AddParsedSubObject ( _
	obj As Object _


Type: System.Object
An Object that represents the parsed element.


obj is not of type LiteralControl.

The following code example demonstrates how to override the AddParsedSubObject method in a custom server control so that it always sets the Text property to the parsed object's Text property, if the parsed object is a Literal, and to an empty string otherwise.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" >
        <title>Custom LiteralControl - AddParsedSubObject - VB.Net Example</title>
       <script runat="server">
      Sub Button1_Click(sender As Object, e As EventArgs)

         Literal1.Text = "Welcome to ASP.NET!"

      End Sub

        <form id="Form1" method="post" runat="server">
            <h3>Custom LiteralControl - AddParsedSubObject - VB.Net Example</h3>

            <aspSample:CustomLiteralAddParsedSubObject id="Literal1" 
              runat="server" text="Literal Text" />

      <br /><br />

      <asp:Button id="Button1"

    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomLiteralAddParsedSubObject
        Inherits System.Web.UI.WebControls.Literal

        Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)

            ' If the server control contains any child controls.
            If Me.HasControls() Then

                ' Notify the base server control that an element, either XML or HTML, 
                ' was parsed, and adds the element to the server control's 
                ' ControlCollection object.
                ' Else the server control doesn't contain any child controls.
                ' If the parsed element is a LiteralControl.
                If TypeOf obj Is System.Web.UI.LiteralControl Then

                    ' Set the server control's Text property to the parsed element's Text value.
                    Me.Text = CType(obj, System.Web.UI.LiteralControl).Text

                    ' Else the parsed element is not a LiteralControl.
                    ' If the server control has a value in the the Text property.
                    Dim currentText As String = Me.Text
                    If currentText.Length <> 0 Then

                        ' Set the server control's Text property to an empty string.
                        Me.Text = System.String.Empty

                        ' Notify the base server control that a new LiteralControl was parsed, 
                        ' and adds the element to the server control's ControlCollection object.
                        MyBase.AddParsedSubObject(New System.Web.UI.LiteralControl(currentText))
                    End If
                End If
            End If
        End Sub
    End Class

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.