Export (0) Print
Expand All

TextBox.AddParsedSubObject Method

This method supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Overridden to allow only literal controls to be added as the Text property.

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

protected override void AddParsedSubObject (
	Object obj
)
protected void AddParsedSubObject (
	Object obj
)
protected override function AddParsedSubObject (
	obj : Object
)

Parameters

obj

An Object that represents the parsed element.

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 control, and throws an exception otherwise.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<HTML>
	<HEAD>
		<title>Custom TextBox - AddParsedSubObject - C# Example</title>
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<h3>Custom TextBox - AddParsedSubObject - C# Example</h3>
			
			<aspSample:CustomTextBoxAddParsedSubObject 
			  id="TextBox1" 
			  runat="server">Hello World!
			</aspSample:CustomTextBoxAddParsedSubObject>
			
		</form>
	</body>
</HTML>

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" AutoEventWireup="True" %>
<HTML>
    <HEAD>
        <title>Custom TextBox - AddParsedSubObject - VJ# Example</title>
    </HEAD>
    <body>
        <form id="Form1" method="get" runat="server" title="Custom TextBox - AddParsedSubObject - VJ# Example" language="VJ#">
            <h3>Custom TextBox - AddParsedSubObject - VJ# Example</h3>
            
            <aspSample:CustomTextBoxAddParsedSubObject 
              id="TextBox1" 
              runat="server"
              text="Hello World!">
            </aspSample:CustomTextBoxAddParsedSubObject>
            
        </form>
    </body>
</HTML>

using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomTextBoxAddParsedSubObject : System.Web.UI.WebControls.TextBox
  {
    protected override void AddParsedSubObject(object obj)
    {
      // If the object is a LiteralControl, then set this control's Text property.
      if (obj is System.Web.UI.LiteralControl) 
      {
        this.Text = ((System.Web.UI.LiteralControl)obj).Text;
      }
      else 
      {
        throw new System.Web.HttpException("You cannot have a child control of type " + obj.GetType().Name.ToString());
      }
    }
  }
}

package Samples.AspNet.JSL.Controls; 

public class CustomTextBoxAddParsedSubObject
    extends System.Web.UI.WebControls.TextBox
{
    protected void AddParsedSubObject(Object obj) 
        throws System.Web.HttpException
    {
        // If the object is a LiteralControl, then set this control's 
        // Text property.
        if (obj instanceof System.Web.UI.LiteralControl) {
            this.set_Text(((System.Web.UI.LiteralControl)obj).get_Text());
        }
        else {
            throw new System.Web.HttpException("You cannot have a child "
                + "control of type " 
                + obj.GetType().get_Name().ToString());
        }
    } //AddParsedSubObject
} //CustomTextBoxAddParsedSubObject

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft