要素が解析されたことをコントロールに通知し、その要素を HyperLink コントロールに追加します。
名前空間: 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。
解説
このメソッドは、カスタム コントロールを HyperLink クラスから派生させる場合に、主に開発者によって使用されます。
入力オブジェクトが LiteralControl であり、HyperLink コントロールに子コントロールがない場合、その入力オブジェクトを使用してコントロールの Text プロパティが設定されます。それ以外の場合は、基本クラス Control の AddParsedSubObject メソッドが呼び出され、指定したオブジェクトが Controls コレクションに追加されます。
使用例
カスタム HyperLink サーバー コントロールの AddParsedSubObject メソッドをオーバーライドして、解析されるオブジェクトが Literal の場合は、常にテキスト プロパティを解析されるオブジェクトのテキスト プロパティに設定し、それ以外の場合は空の文字列に設定する方法を次のコード例に示します。
<%@ 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 HyperLink - AddParsedSubObject - VB.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom HyperLink - AddParsedSubObject - VB.NET Example</h3>
<aspSample:CustomHyperLinkAddParsedSubObject
id="HyperLink1" runat="server" Target="_blank"
href="https://www.microsoft.com/"
ToolTip="Microsoft Web Site">www.microsoft.com
</aspSample:CustomHyperLinkAddParsedSubObject>
</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 HyperLink - AddParsedSubObject - C# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom HyperLink - AddParsedSubObject - C# Example</h3>
<aspSample:CustomHyperLinkAddParsedSubObject
id="HyperLink1" runat="server" Target="_blank"
href="https://www.microsoft.com/"
ToolTip="Microsoft Web Site">www.microsoft.com
</aspSample:CustomHyperLinkAddParsedSubObject>
</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 HyperLink - AddParsedSubObject - VJ# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom HyperLink - AddParsedSubObject - VJ# Example</h3>
<aspSample:CustomHyperLinkAddParsedSubObject
id="HyperLink1" runat="server" Target="_blank"
href="https://www.microsoft.com/"
ToolTip="Microsoft Web Site">www.microsoft.com
</aspSample:CustomHyperLinkAddParsedSubObject>
</form>
</body>
</html>
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomHyperLinkAddParsedSubObject
Inherits System.Web.UI.WebControls.HyperLink
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.
MyBase.AddParsedSubObject(obj)
' Else the server control doesn't contain any child controls.
Else
' 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.
Else
' 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
MyBase.AddParsedSubObject(obj)
End If
End If
End Sub
End Class
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomHyperLinkAddParsedSubObject : System.Web.UI.WebControls.HyperLink
{
protected override void AddParsedSubObject(object obj)
{
// If the server control contains any child controls.
if (this.HasControls())
{
// 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.
base.AddParsedSubObject(obj);
}
// Else the server control doesn't contain any child controls.
else
{
// If the parsed element is a LiteralControl.
if (obj is System.Web.UI.LiteralControl)
{
// Set the server control's Text property to the parsed element's Text value.
this.Text = ((System.Web.UI.LiteralControl)obj).Text;
}
// Else the parsed element is not a LiteralControl.
else
{
// If the server control has a value in the the Text property.
string currentText = this.Text;
if (currentText.Length != 0)
{
// Set the server control's Text property to an empty string.
this.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.
base.AddParsedSubObject(new System.Web.UI.LiteralControl(currentText));
}
base.AddParsedSubObject(obj);
}
}
}
}
}
package Samples.AspNet.JSL.Controls;
public class CustomHyperLinkAddParsedSubObject
extends System.Web.UI.WebControls.HyperLink
{
protected void AddParsedSubObject(Object obj)
{
// If the server control contains any child controls.
if (this.HasControls()) {
// 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.
super.AddParsedSubObject(obj);
}
// Else the server control doesn't contain any child controls.
else {
// If the parsed element is a LiteralControl.
if (obj instanceof System.Web.UI.LiteralControl) {
// Set the server control's Text property to the
// parsed element's Text value.
this.set_Text(((System.Web.UI.LiteralControl)obj).get_Text());
}
// Else the parsed element is not a LiteralControl.
else {
// If the server control has a value in the the Text property.
String currentText = this.get_Text();
if (currentText.get_Length() != 0) {
// Set the server control's Text property to an empty string.
this.set_Text("");
// Notify the base server control that a new LiteralControl
// was parsed,
// and adds the element to the server control's
// ControlCollection object.
super.AddParsedSubObject(new System.Web.UI.
LiteralControl(currentText));
}
super.AddParsedSubObject(obj);
}
}
} //AddParsedSubObject
} //CustomHyperLinkAddParsedSubObject
プラットフォーム
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
参照
関連項目
HyperLink クラス
HyperLink メンバ
System.Web.UI.WebControls 名前空間
HasControls