LinkButton.AddParsedSubObject-Methode
Benachrichtigt das Steuerelement, dass entweder ein XML- oder ein HTML-Element analysiert wurde, und fügt das Element dem ControlCollection-Objekt des Steuerelements hinzu.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Protected Overrides Sub AddParsedSubObject ( _
obj As Object _
)
'Usage
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
)
Parameter
- obj
Ein Object, das das analysierte Element darstellt.
Beispiel
Das folgende Codebeispiel veranschaulicht, wie Sie die AddParsedSubObject-Methode in einem benutzerdefinierten LinkButton-Serversteuerelement überschreiben können, sodass es die Texteigenschaft auf die Texteigenschaft des analysierten Objekts festlegt, sofern es sich beim analysierten Objekt um ein Literal-Objekt handelt. Andernfalls wird eine leere Zeichenfolge festgelegt.
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VS.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<HTML>
<HEAD>
<title>Custom LinkButton - AddParsedSubObject - VB.NET Example</title>
<script runat="server">
Sub LinkButton1_Command(sender As Object, e As CommandEventArgs)
' Redirect to the Microsoft home page.
Response.Redirect("https://www.microsoft.com/")
End Sub
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom LinkButton - AddParsedSubObject - VB.NET Example</h3>
<aspSample:CustomLinkButtonAddParsedSubObject id="LinkButton1"
runat="server" OnCommand="LinkButton1_Command"
ToolTip="Microsoft Home">Microsoft Corp.</aspSample:CustomLinkButtonAddParsedSubObject>
</form>
</body>
</HTML>
...
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomLinkButtonAddParsedSubObject
Inherits System.Web.UI.WebControls.LinkButton
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
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<HTML>
<HEAD>
<title>Custom LinkButton - AddParsedSubObject - C# Example</title>
<script runat="server">
void LinkButton1_Command(Object sender, CommandEventArgs e)
{
// Redirect to the Microsoft home page.
Response.Redirect("https://www.microsoft.com/");
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom LinkButton - AddParsedSubObject - C# Example</h3>
<aspSample:CustomLinkButtonAddParsedSubObject
id="LinkButton1"
runat="server"
OnCommand="LinkButton1_Command"
ToolTip="Microsoft Home">Microsoft Corp.
</aspSample:CustomLinkButtonAddParsedSubObject>
</form>
</body>
</HTML>
...
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomLinkButtonAddParsedSubObject : System.Web.UI.WebControls.LinkButton
{
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 // Else the server control doesn't contain any child controls.
{
// 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 // Else the parsed element is not a LiteralControl.
{
// 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);
}
}
}
}
}
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" AutoEventWireup="True" %>
<HTML>
<HEAD>
<title>Custom LinkButton - AddParsedSubObject - VJ# Example</title>
<script runat="server">
void LinkButton1_Command(Object sender, CommandEventArgs e)
{
// Redirect to the Microsoft home page.
get_Response().Redirect("https://www.microsoft.com/");
} //LinkButton1_Command
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom LinkButton - AddParsedSubObject - VJ# Example</h3>
<aspSample:CustomLinkButtonAddParsedSubObject
id="LinkButton1"
runat="server"
OnCommand="LinkButton1_Command"
ToolTip="Microsoft Home">Microsoft Corp.
</aspSample:CustomLinkButtonAddParsedSubObject>
</form>
</body>
</HTML>
...
package Samples.AspNet.JSL.Controls;
public class CustomLinkButtonAddParsedSubObject
extends System.Web.UI.WebControls.LinkButton
{
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
} //CustomLinkButtonAddParsedSubObject
Plattformen
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 unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
LinkButton-Klasse
LinkButton-Member
System.Web.UI.WebControls-Namespace
Literal