LinkButton.AddParsedSubObject Method
.NET Framework 2.0
Notifies the control that an element, either XML or HTML, was parsed, and adds the element to the control's ControlCollection object.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
The following code example demonstrates how to override the AddParsedSubObject method in a custom LinkButton server control so that it either sets the text property to the parsed object's text property, if the parsed object is a Literal object, or to an empty string otherwise.
<%@ 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("http://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
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.
Community Additions
ADD
Show: