ControlDesigner.GetDesignTimeHtml Método

Definição

Recupera a marcação HTML usada para representar o controle em tempo de design.

Sobrecargas

GetDesignTimeHtml(DesignerRegionCollection)

Recupera a marcação HTML para exibir o controle e preenche a coleção com as regiões de designer de controle atuais.

GetDesignTimeHtml()

Recupera a marcação HTML usada para representar o controle em tempo de design.

GetDesignTimeHtml(DesignerRegionCollection)

Recupera a marcação HTML para exibir o controle e preenche a coleção com as regiões de designer de controle atuais.

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

Parâmetros

regions
DesignerRegionCollection

Uma coleção de regiões de designer de controle do controle associado.

Retornos

String

A marcação HTML do tempo de design do controle associado, incluindo todas as regiões de designer de controle.

Exemplos

O exemplo de código a seguir mostra como criar marcação HTML usando a DesignerRegionCollection coleção.

// 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

Comentários

O host de design chama o GetDesignTimeHtml método para obter a marcação HTML em tempo de design e a lista atual de regiões do designer de controle. Usando o DesignerRegionCollection, o host de design pode solicitar a marcação para cada região do designer de controle editável.

O GetDesignTimeHtml método é fornecido para um designer de controle derivado, como a GridViewDesigner classe, que deve processar o conteúdo da região antes de chamar o GetDesignTimeHtml método.

Confira também

Aplica-se a

GetDesignTimeHtml()

Recupera a marcação HTML usada para representar o controle em tempo de design.

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

Retornos

String

A marcação HTML usada para representar o controle em tempo de design.

Exemplos

O exemplo de código a seguir demonstra como substituir o GetDesignTimeHtml método em um designer de controle personalizado. Se a propriedade Text do controle associado estiver vazia, o GetDesignTimeHtml método chamará o GetEmptyDesignTimeHtml método. Caso contrário, o GetDesignTimeHtml método cria e renderiza um controle 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

Notas aos Herdeiros

Se você estiver criando um controle de contêiner personalizado, certifique-se de renderizar o controle e todos os controles filho em tempo de design, independentemente de a Visible propriedade estar definida true como ou false.

Confira também

Aplica-se a