TextBox.AddParsedSubObject メソッド
アセンブリ: System.Web (system.web.dll 内)


カスタム サーバー コントロールの AddParsedSubObject メソッドをオーバーライドして、解析するオブジェクトが Literal コントロールの場合は、Text プロパティに解析するオブジェクトの Text プロパティを必ず設定し、それ以外の場合は例外をスローする方法を次のコード例に示します。
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %> <%@ Page Language="VB" AutoEventWireup="True" %> <HTML> <HEAD> <title>Custom TextBox - AddParsedSubObject - VB.NET Example</title> </HEAD> <body> <form id="Form1" method="post" runat="server"> <h3>Custom TextBox - AddParsedSubObject - VB.NET Example</h3> <aspSample:CustomTextBoxAddParsedSubObject id="TextBox1" runat="server">Hello World!</aspSample:CustomTextBoxAddParsedSubObject> </form> </body> </HTML>
<%@ 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>
Imports System.Web Imports System.Security.Permissions Namespace Samples.AspNet.VB.Controls <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _ Public NotInheritable Class CustomTextBoxAddParsedSubObject Inherits System.Web.UI.WebControls.TextBox Protected Overrides Sub AddParsedSubObject(ByVal obj As Object) ' If the object is a LiteralControl, then set this control's Text property. If TypeOf obj Is System.Web.UI.LiteralControl Then Me.Text = CType(obj, System.Web.UI.LiteralControl).Text Else Throw New System.Web.HttpException("You cannot have children controls of type " + obj.GetType().Name.ToString()) End If End Sub End Class End Namespace
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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- TextBox.AddParsedSubObject メソッドのページへのリンク