语言

ControlDesigner.GetEmptyDesignTimeHtml 方法

定义

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

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实现中调用该方法。

适用于

另请参阅