语言

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 标记,包括所有控件设计器区域。

示例

下面的代码示例演示如何使用 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。

另请参阅

适用于