ControlBuilder.HasBody-Methode
Bestimmt, ob ein Steuerelement sowohl ein öffnendes als auch ein schließendes Tag besitzt. Diese Methode wird vom ASP.NET-Seitenframework aufgerufen.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Public Overridable Function HasBody As Boolean
'Usage
Dim instance As ControlBuilder
Dim returnValue As Boolean
returnValue = instance.HasBody
public virtual bool HasBody ()
public:
virtual bool HasBody ()
public boolean HasBody ()
public function HasBody () : boolean
Rückgabewert
true, wenn das Steuerelement ein Start- und ein Endtag besitzt, andernfalls false.
Hinweise
Diese Methode wird vom ASP.NET-Seitenframework während der Analyse aufgerufen und ist nicht für den direkten Aufruf im Code gedacht.
Beispiel
In diesem Beispiel wird die OnAppendToParentBuilder-Methode überschrieben, um anhand einer Überprüfung der ControlType-Eigenschaft zu bestimmen, auf welchen Steuerelementtyp dieser Generator angewendet wird. Im Falle einer CustomTextBox überprüft der Generator, ob der Wert der HasAspCode-Eigenschaft im Steuerelement enthalten ist. Wenn dies der Fall ist, wird eine Ausnahme ausgelöst, ansonsten wird die HasBody-Methode aufgerufen.
Imports System
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
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();
}
}
}
}
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
ControlBuilder-Klasse
ControlBuilder-Member
System.Web.UI-Namespace