ControlDesigner.GetDesignTimeHtml 方法

定義

擷取在設計階段用來表示控制項的 HTML 標記。

多載

GetDesignTimeHtml(DesignerRegionCollection)

擷取要顯示控制項的 HTML 標記,並將目前控制項設計工具區域填入集合中。

GetDesignTimeHtml()

擷取在設計階段用來表示控制項的 HTML 標記。

GetDesignTimeHtml(DesignerRegionCollection)

擷取要顯示控制項的 HTML 標記,並將目前控制項設計工具區域填入集合中。

public:
 virtual System::String ^ GetDesignTimeHtml(System::Web::UI::Design::DesignerRegionCollection ^ regions);
public virtual string GetDesignTimeHtml (System.Web.UI.Design.DesignerRegionCollection regions);
abstract member GetDesignTimeHtml : System.Web.UI.Design.DesignerRegionCollection -> string
override this.GetDesignTimeHtml : System.Web.UI.Design.DesignerRegionCollection -> string
Public Overridable Function GetDesignTimeHtml (regions As DesignerRegionCollection) As String

參數

regions
DesignerRegionCollection

相關聯控制項的控制項設計工具區域集合。

傳回

相關聯控制項的設計階段 HTML 標記 (包含所有控制項設計工具區域)。

範例

下列程式碼範例示範如何使用 集合建立 HTML 標籤 DesignerRegionCollection

// Create the regions and design-time markup. Called by the designer host.
public override String GetDesignTimeHtml(DesignerRegionCollection regions) {
    // Create 3 regions: 2 clickable headers and an editable row
    regions.Add(new DesignerRegion(this, "Header0"));
    regions.Add(new DesignerRegion(this, "Header1"));

    // Create an editable region and add it to the regions
    EditableDesignerRegion editableRegion = 
        new EditableDesignerRegion(this, 
            "Content" + myControl.CurrentView, false);
    regions.Add(editableRegion);

    // Set the highlight for the selected region
    regions[myControl.CurrentView].Highlight = true;

    // Use the base class to render the markup
    return base.GetDesignTimeHtml();
}
' Create the regions and design-time markup. Called by the designer host.
Public Overrides Function GetDesignTimeHtml(ByVal regions As DesignerRegionCollection) As String
    ' Create 3 regions: 2 clickable headers and an editable row
    regions.Add(New DesignerRegion(Me, "Header0"))
    regions.Add(New DesignerRegion(Me, "Header1"))

    ' Create an editable region and add it to the regions
    Dim editableRegion As EditableDesignerRegion = _
        New EditableDesignerRegion(Me, _
            "Content" & myControl.CurrentView, False)
    regions.Add(editableRegion)

    ' Set the highlight for the selected region
    regions(myControl.CurrentView).Highlight = True

    ' Use the base class to render the markup
    Return MyBase.GetDesignTimeHtml()
End Function

備註

設計主機會 GetDesignTimeHtml 呼叫 方法來取得設計階段 HTML 標籤和控制項設計工具區域的目前清單。 使用 DesignerRegionCollection,設計主機接著可以要求每個可編輯控制項設計工具區域的標記。

方法 GetDesignTimeHtml 會提供給衍生控制項設計工具,例如 GridViewDesigner 類別,該類別必須先處理區域的內容,然後再呼叫 GetDesignTimeHtml 方法。

另請參閱

適用於

GetDesignTimeHtml()

擷取在設計階段用來表示控制項的 HTML 標記。

public:
 virtual System::String ^ GetDesignTimeHtml();
public virtual string GetDesignTimeHtml ();
abstract member GetDesignTimeHtml : unit -> string
override this.GetDesignTimeHtml : unit -> string
Public Overridable Function GetDesignTimeHtml () 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

給繼承者的注意事項

如果您要建立自訂容器控制項,請確定您在設計階段轉譯控制項和所有子控制項,不論屬性是 Visible 設定 true 為 或 false

另請參閱

適用於