ControlBuilder.OnAppendToParentBuilder(ControlBuilder) 方法

定義

告知 ControlBuilder 已經加入到父控制項產生器中。Notifies the ControlBuilder that it is being added to a parent control builder.

public:
 virtual void OnAppendToParentBuilder(System::Web::UI::ControlBuilder ^ parentBuilder);
public virtual void OnAppendToParentBuilder (System.Web.UI.ControlBuilder parentBuilder);
abstract member OnAppendToParentBuilder : System.Web.UI.ControlBuilder -> unit
override this.OnAppendToParentBuilder : System.Web.UI.ControlBuilder -> unit
Public Overridable Sub OnAppendToParentBuilder (parentBuilder As ControlBuilder)

參數

parentBuilder
ControlBuilder

將目前產生器加入的 ControlBuilder 物件。The ControlBuilder object to which the current builder is added.

範例

這個範例會覆寫 OnAppendToParentBuilder 方法來檢查 ControlType 屬性,以決定要套用此產生器的控制項類型。This example overrides the OnAppendToParentBuilder method to check the ControlType property to determine what type of control this builder is applied to. 如果是 CustomTextBox,產生器會檢查控制項中是否包含 HasAspCode 屬性的值。If it is a CustomTextBox, the builder checks whether the value of the HasAspCode property is included in the control. 若是如此,則會擲回例外狀況(如果不是呼叫 HasBody 方法)。If so, an exception is thrown, if not the HasBody method is called.

using System;
using System.Web.UI;
using System.Web;
using System.Security.Permissions;

namespace ASPNET.Samples
{
    [
    AspNetHostingPermission(SecurityAction.Demand,
        Level=AspNetHostingPermissionLevel.Minimal)
    ]
    public class AppendControlBuilder : ControlBuilder
    {
        // Override the OnAppendToParentBuilder method.
        public override void OnAppendToParentBuilder(ControlBuilder parentBuilder)
        {
            // Check whether the type of the control this builder
            // is applied to is CustomTextBox. If so, check whether
            // ASP code blocks exist in the control. If so, call
            // throw an Exception, if not, call the HasBody method.        
            if (ControlType == Type.GetType("CustomTextBox"))
            {
                if (HasAspCode)
                    throw new Exception("This control cannot contain code blocks.");
                else
                    HasBody();
            }
        }
    }
}
Imports System.Web.UI
Imports System.Web
Imports System.Security.Permissions

Namespace ASPNET.Samples

   <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
   Public NotInheritable Class AppendControlBuilder
      Inherits ControlBuilder

      ' Override the OnAppendToParentBuilder method.
      Overrides Public Sub OnAppendToParentBuilder( _
         ByVal parentBuilder As ControlBuilder _
      )
            ' Check whether the type of the control this builder
            ' is applied to is CustomTextBox. If so, check whether
            ' ASP code blocks exist in the control. If so, call
            ' throw an Exception, if not, call the HasBody method.        
            If ControlType Is Type.GetType("CustomTextBox") Then
                If HasAspCode = True Then
                    Throw New Exception("This control cannot contain code blocks.")
                Else
                    HasBody()
                End If
            End If

        End Sub

   End Class

End Namespace

適用於