ControlDesigner.GetEmptyDesignTimeHtml メソッド

定義

実行時に視覚的な表現を持たない Web サーバー コントロールをデザイン時に表す 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 メソッドの既定の動作では、コンポーネントの名前を含む文字列が返されます。 デザイン時の HTML マークアップがない場合は、GetDesignTimeHtml メソッドの実装で GetEmptyDesignTimeHtml メソッドを呼び出す必要があります。

適用対象

こちらもご覧ください