ControlDesigner.GetEditableDesignerRegionContent 方法

定义

返回关联控件设计时视图中可编辑区域的内容。

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 对象。

返回

如果控件设计器支持可编辑区域,则为区域的保持内容;否则为空字符串 ("")。

示例

下面的代码示例演示如何获取对设计宿主的引用,然后使用该引用创建 ControlParser 对象,该对象为 region 及其内容创建 HTML 标记。

// 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 返回空字符串 (“”) 。

派生自 类的 ControlDesigner 类可以在设计图面上支持基于区域的编辑,并重写 GetEditableDesignerRegionContent 方法以返回指定区域的内容。

适用于

另请参阅