ControlDesigner.GetDesignTimeHtml 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
擷取設計時用來表示控制項的 HTML 標記。
多載
| 名稱 | Description |
|---|---|
| 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 標記,涵蓋相關控制項,包括所有控制設計區。
範例
以下程式碼範例展示了如何使用該 DesignerRegionCollection 集合來建立 HTML 標記。
// 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 方法會建立並渲染超連結控制項。
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。
另請參閱
- GetEmptyDesignTimeHtml()
- GetErrorDesignTimeHtml(Exception)
- GetDesignTimeHtml(DesignerRegionCollection)
- ASP.NET 控制設計師概述