HyperLink.AddParsedSubObject(Object) 메서드

정의

요소가 구문 분석되었음을 컨트롤에 알리고 이 요소를 HyperLink 컨트롤에 추가합니다.

protected:
 override void AddParsedSubObject(System::Object ^ obj);
protected override void AddParsedSubObject (object obj);
override this.AddParsedSubObject : obj -> unit
Protected Overrides Sub AddParsedSubObject (obj As Object)

매개 변수

obj
Object

구문 분석한 요소를 나타내는 Object입니다.

예제

다음 코드 예제에는 재정의 하는 방법을 보여 줍니다.는 AddParsedSubObject 사용자 지정의 메서드 HyperLink 구문 분석 된 개체가 있으면 구문 분석 된 개체의 text 속성을 text 속성을 항상 설정 되도록 서버 컨트롤을 Literal, 및 빈 문자열을 그렇지 않은 경우.

<%@ 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"
              NavigateUrl="http://www.microsoft.com/"  
              ToolTip="Microsoft Web Site">www.microsoft.com
            </aspSample:CustomHyperLinkAddParsedSubObject>

        </form>
    </body>
</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 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"
             NavigateUrl="http://www.microsoft.com/"  
             ToolTip="Microsoft Web Site">www.microsoft.com
            </aspSample:CustomHyperLinkAddParsedSubObject>

        </form>
    </body>
</html>
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 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);
        }
      }
    }
  }
}
<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 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

설명

사용자 지정 컨트롤을 파생 하는 경우 주로 컨트롤 개발자가이 메서드는는 HyperLink 클래스입니다.

입력 개체가 LiteralControl, 및 HyperLink 컨트롤에 자식 컨트롤이 없는 다음 입력된 개체는 설정 하는 데 사용 되는 Text 컨트롤의 속성입니다. 이 고, 그렇지 합니다 AddParsedSubObject 메서드는 기본 Control 클래스에서 호출 되 고 지정된 된 개체에 추가 됩니다는 Controls 컬렉션입니다.

적용 대상

추가 정보