ControlDesigner.GetEmptyDesignTimeHtml 方法

定义

检索表示在设计时将不具有可视表示形式的运行时 Web 服务器控件的 HTML 标记。

protected:
 virtual System::String ^ GetEmptyDesignTimeHtml();
protected virtual string GetEmptyDesignTimeHtml ();
abstract member GetEmptyDesignTimeHtml : unit -> string
override this.GetEmptyDesignTimeHtml : unit -> string
Protected Overridable Function GetEmptyDesignTimeHtml () As String

返回

用于在设计时表示控件的 HTML 标记,若无该标记,则控件将没有可视表示形式。 默认值为包含组件类型和 ID 的矩形。

示例

下面的代码示例演示如何在自定义控件设计器中重写 GetDesignTimeHtml 方法。 Text如果关联控件的 属性为空,该方法GetDesignTimeHtml将调用 GetEmptyDesignTimeHtml 方法。 否则, GetDesignTimeHtml 方法将创建并呈现控件 Hyperlink

public override string GetDesignTimeHtml()
{
    if (simpleControl.Text.Length > 0)
    {
        string spec = "<a href='{0}.aspx'>{0}</a>";
        return String.Format(spec, simpleControl.Text);
    }
    else
    {
        return GetEmptyDesignTimeHtml();
    }
}
Public Overrides Function GetDesignTimeHtml() As String
   ' Component is the instance of the component or control that
   ' this designer object is associated with. This property is 
   ' inherited from System.ComponentModel.ComponentDesigner.
   simpleControl = CType(Component, Simple)
   
   If simpleControl.Text.Length > 0 Then
      Dim sw As New StringWriter()
      Dim tw As New HtmlTextWriter(sw)
      
      Dim placeholderLink As New HyperLink()
      
      ' Put simpleControl.Text into the link's Text.
      placeholderLink.Text = simpleControl.Text
      placeholderLink.NavigateUrl = simpleControl.Text
      placeholderLink.RenderControl(tw)
      
      Return sw.ToString()
   Else
      Return GetEmptyDesignTimeHtml()
   End If
End Function

注解

方法的默认行为 GetEmptyDesignTimeHtml 是返回包含组件名称的字符串。 GetEmptyDesignTimeHtml如果没有设计时 HTML 标记,则应在方法的GetDesignTimeHtml实现中调用 方法。

适用于

另请参阅