ControlDesigner.GetEditableDesignerRegionContent(EditableDesignerRegion) 方法

定义

返回关联控件设计时视图中可编辑区域的内容。Returns the content for an editable region of the design-time view of the associated control.

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

参数

region
EditableDesignerRegion

要获取其内容的 EditableDesignerRegion 对象。The EditableDesignerRegion object to get content for.

返回

String

如果控件设计器支持可编辑区域,则为区域的保持内容;否则为空字符串 ("")。The persisted content for the region, if the control designer supports editable regions; otherwise, an empty string ("").

示例

下面的代码示例演示如何获取对设计宿主的引用,然后使用该引用创建一个 ControlParser 对象,该对象为及其内容创建 HTML 标记 regionThe following code example shows how to get a reference to the design host, and then use the reference to create a ControlParser object that creates the HTML markup for region and its contents.

// Get the content string for the selected region. Called by the designer host?
public override string GetEditableDesignerRegionContent(EditableDesignerRegion region) 
{
    // Get a reference to the designer host
    IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));
    if (host != null)
    {
        ITemplate template = myControl.View1;
        if (region.Name == "Content1")
            template = myControl.View2;

        // Persist the template in the design host
        if (template != null)
            return ControlPersister.PersistTemplate(template, host);
    }

    return String.Empty;
}
' Get the content string for the selected region. Called by the designer host?
Public Overrides Function GetEditableDesignerRegionContent(ByVal region As EditableDesignerRegion) As String
    ' Get a reference to the designer host
    Dim host As IDesignerHost = CType(Component.Site.GetService(GetType(IDesignerHost)), IDesignerHost)

    If Not IsNothing(host) Then
        Dim template As ITemplate = myControl.View1
        If region.Name = "Content1" Then
            template = myControl.View2
        End If

        ' Persist the template in the design host
        If Not IsNothing(template) Then
            Return ControlPersister.PersistTemplate(template, host)
        End If
    End If

    Return String.Empty
End Function

注解

此方法的默认实现 GetEditableDesignerRegionContent 返回空字符串 ( "" ) 。The default implementation of the GetEditableDesignerRegionContent method returns an empty string ("").

从类派生的类 ControlDesigner 可以支持设计图面上基于区域的编辑,并重写 GetEditableDesignerRegionContent 方法以返回指定区域的内容。Classes deriving from the ControlDesigner class can support region-based editing on the design surface and override the GetEditableDesignerRegionContent method to return the content for a specified region.

适用于

另请参阅