ControlDesigner.GetEmptyDesignTimeHtml 方法
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
检索表示在设计时将不具有可视表示形式的运行时 Web 服务器控件的 HTML 标记。
protected:
virtual System::String ^ GetEmptyDesignTimeHtml();
C#
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
控件。
C#
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实现中调用 方法。
产品 | 版本 |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |