ControlDesigner.GetDesignTimeHtml Metoda

Definice

Načte kód HTML, který se používá k reprezentaci ovládacího prvku v době návrhu.

Přetížení

GetDesignTimeHtml(DesignerRegionCollection)

Načte kód HTML pro zobrazení ovládacího prvku a naplní kolekci aktuálními oblastmi návrháře ovládacích prvků.

GetDesignTimeHtml()

Načte kód HTML, který se používá k reprezentaci ovládacího prvku v době návrhu.

GetDesignTimeHtml(DesignerRegionCollection)

Načte kód HTML pro zobrazení ovládacího prvku a naplní kolekci aktuálními oblastmi návrháře ovládacích prvků.

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

Parametry

regions
DesignerRegionCollection

Kolekce oblastí návrháře ovládacích prvků pro přidružený ovládací prvek.

Návraty

Značky HTML v době návrhu přidruženého ovládacího prvku, včetně všech oblastí návrháře ovládacích prvků

Příklady

Následující příklad kódu ukazuje, jak vytvořit značky HTML pomocí DesignerRegionCollection kolekce.

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

Poznámky

Hostitel návrhu volá metodu GetDesignTimeHtml , aby získal kód HTML v době návrhu a aktuální seznam oblastí návrháře ovládacích prvků. Pomocí DesignerRegionCollection pak může hostitel návrhu požádat o značky pro každou upravitelnou oblast návrháře ovládacího prvku.

Metoda GetDesignTimeHtml je k dispozici pro návrhář odvozených ovládacích prvků, jako GridViewDesigner je třída, která musí zpracovat obsah pro oblast před voláním GetDesignTimeHtml metody.

Viz také

Platí pro

GetDesignTimeHtml()

Načte kód HTML, který se používá k reprezentaci ovládacího prvku v době návrhu.

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

Návraty

Značky HTML použité k reprezentaci ovládacího prvku v době návrhu.

Příklady

Následující příklad kódu ukazuje, jak přepsat metodu GetDesignTimeHtml v návrháři vlastních ovládacích prvků. Pokud text vlastnost přidruženého ovládacího prvku je prázdná, GetDesignTimeHtml metoda volá metodu GetEmptyDesignTimeHtml . V opačném GetDesignTimeHtml případě metoda vytvoří a vykreslí hypertextový odkaz ovládací prvek.

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

Poznámky pro dědice

Pokud vytváříte vlastní ovládací prvek kontejneru, ujistěte se, že jste tento ovládací prvek a všechny podřízené ovládací prvky vykreslili v době návrhu Visible bez ohledu na to, jestli je vlastnost nastavená na true nebo false.

Viz také

Platí pro