HyperLink.AddParsedSubObject Method
.NET Framework 3.0
Notifies the control that an element was parsed, and adds the element to the HyperLink control.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
This method is used primarily by control developers, when deriving a custom control from the HyperLink class.
If the input object is a LiteralControl, and the HyperLink control has no child controls, then the input object is used to set the Text property of the control. Otherwise, the AddParsedSubObject method of the base Control class is called and the specified object is added to the Controls collection.
The following code example demonstrates how to override the AddParsedSubObject method in a custom HyperLink server control so that it always sets the text property to the parsed object's text property, if the parsed object is a Literal, and to an empty string otherwise.
<%@ 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"
NavigateUrl="http://www.microsoft.com/"
ToolTip="Microsoft Web Site">www.microsoft.com
</aspSample:CustomHyperLinkAddParsedSubObject>
</form>
</body>
</html>
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
Community Additions
ADD
Show: