このメソッドは,.NET Framework インフラストラクチャをサポートします。独自に作成したコードから直接使用するためのものではありません。
リテラル コントロールだけを Text プロパティとして追加できるようにオーバーライドされます。
名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Protected Overrides Sub AddParsedSubObject ( _
obj As Object _
)
'使用
Dim obj As Object
Me.AddParsedSubObject(obj)
protected override void AddParsedSubObject (
Object obj
)
protected:
virtual void AddParsedSubObject (
Object^ obj
) override
protected void AddParsedSubObject (
Object obj
)
protected override function AddParsedSubObject (
obj : Object
)
適用できません。
パラメータ
- obj
解析された要素を表す Object。
例外
例外の種類 | 条件 |
---|---|
obj が LiteralControl 型ではありません。 |
使用例
カスタム サーバー コントロールの AddParsedSubObject メソッドをオーバーライドして、解析するオブジェクトが Literal コントロールの場合は、Text プロパティに解析するオブジェクトの Text プロパティを必ず設定し、それ以外の場合は例外をスローする方法を次のコード例に示します。
![]() |
---|
この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。詳細については、「スクリプトによる攻略の概要」を参照してください。 |
<%@ 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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Custom TextBox - AddParsedSubObject - VJ# Example</title>
</head>
<body>
<form id="Form1" method="get" runat="server" title="Custom TextBox - AddParsedSubObject - VJ# Example" lang="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 Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
バージョン情報
.NET Framework
サポート対象 : 3.0,2.0,1.1,1.0
参照
関連項目
TextBox クラス
TextBox メンバ
System.Web.UI.WebControls 名前空間
Control.AddParsedSubObject