ControlBuilder.SetTagInnerText(String) 方法

定义

ControlBuilder 提供控件标记的内部文本。

public:
 virtual void SetTagInnerText(System::String ^ text);
public virtual void SetTagInnerText (string text);
abstract member SetTagInnerText : string -> unit
override this.SetTagInnerText : string -> unit
Public Overridable Sub SetTagInnerText (text As String)

参数

text
String

要提供的文本。

示例

以下示例在调用该方法时NeedsTagInnerText使用InDesigner该属性。 当控件附加此生成器时,确定 NeedsTagInnerText 控件是否在设计时通过设计器访问该控件。 返回 NeedsTagInnerText 属性的值 InDesigner ,然后 SetTagInnerText 调用该方法。 如果属性 InDesigner 设置为 false,则会引发一个 Exception 。 否则,在调用时 SetTagInnerText 返回控件的内部文本。

[AspNetHostingPermission(SecurityAction.Demand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class MyControlControlBuilder : ControlBuilder
{
    private string _innerText;

    public override bool NeedsTagInnerText()
    {
        return InDesigner;
    }

    public override void SetTagInnerText(string text)
    {
        if (!InDesigner)
            throw new Exception("The control is not in design mode.");
        else
            _innerText = text;
    }
}
<AspNetHostingPermission(SecurityAction.Demand, _
  Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class MyControlControlBuilder
  Inherits ControlBuilder
    
    Private _innerText As String
    
    Overrides Public Function NeedsTagInnerText() As Boolean
      Return InDesigner
    End Function
    
    Overrides Public Sub SetTagInnerText(ByVal text As String)        
       If InDesigner = False
         Throw New System.Exception("The control is not in design mode.")
       Else
         _innerText = text
       End If
    End Sub
    
End Class

注解

仅当以前返回trueNeedsTagInnerText,才调用此方法。

适用于