ControlDesigner.GetEmptyDesignTimeHtml 方法


检索表示在设计时将不具有可视表示形式的运行时 Web 服务器控件的 HTML 标记。Retrieves the HTML markup to represent a Web server control at design time that will have no visual representation at run time.

 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 标记,若无该标记,则控件将没有可视表示形式。The HTML markup used to represent a control at design time that would otherwise have no visual representation. 默认值为包含组件类型和 ID 的矩形。The default is a rectangle that contains the type and ID of the component.


下面的代码示例演示如何重写自定义控件设计器中的 GetDesignTimeHtml 方法。The following code example demonstrates how to override the GetDesignTimeHtml method in a custom control designer. 如果关联的控件的 Text 属性为空,则 GetDesignTimeHtml 方法将调用 GetEmptyDesignTimeHtml 方法。If the Text property for the associated control is empty, the GetDesignTimeHtml method calls GetEmptyDesignTimeHtml method. 否则,GetDesignTimeHtml 方法创建并呈现 Hyperlink 控件。Otherwise, the GetDesignTimeHtml method creates and renders a Hyperlink control.

public override string GetDesignTimeHtml()
    if (simpleControl.Text.Length > 0)
        string spec = "<a href='{0}.aspx'>{0}</a>";
        return String.Format(spec, simpleControl.Text);
        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
      Return sw.ToString()
      Return GetEmptyDesignTimeHtml()
   End If
End Function


GetEmptyDesignTimeHtml 方法的默认行为是返回包含组件名称的字符串。The default behavior of the GetEmptyDesignTimeHtml method is to return a string that contains the name of the component. 当没有设计时 HTML 标记时,应在 GetDesignTimeHtml 方法的实现中调用 GetEmptyDesignTimeHtml 方法。The GetEmptyDesignTimeHtml method should be called in the implementation of the GetDesignTimeHtml method when there is no design-time HTML markup.