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 標記,用來在設計階段呈現沒有視覺表示的控制項。 預設值是一個包含元件類型和識別碼的矩形。

範例

下列程式碼範例示範如何在自訂控制項設計工具中覆寫 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 應該在 方法的實作中呼叫 方法。

適用於

另請參閱