語言

ControlDesigner.GetEmptyDesignTimeHtml 方法

定義

取得 HTML 標記,以表示設計時的網頁伺服器控制項,執行時不會有視覺化表示。

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中被呼叫。

適用於

另請參閱