ControlDesigner.GetEmptyDesignTimeHtml 方法

定义

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

C#
protected virtual string GetEmptyDesignTimeHtml();

返回

用于在设计时表示控件的 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();
    }
}

注解

方法的默认行为 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

另请参阅