ControlDesigner.GetDesignTimeHtml Metoda

Definicja

Pobiera znaczniki HTML używane do reprezentowania kontrolki w czasie projektowania.

Przeciążenia

GetDesignTimeHtml(DesignerRegionCollection)

Pobiera znacznik HTML, aby wyświetlić kontrolkę i wypełnić kolekcję bieżącymi regionami projektanta kontrolek.

GetDesignTimeHtml()

Pobiera znaczniki HTML używane do reprezentowania kontrolki w czasie projektowania.

GetDesignTimeHtml(DesignerRegionCollection)

Pobiera znacznik HTML, aby wyświetlić kontrolkę i wypełnić kolekcję bieżącymi regionami projektanta kontrolek.

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

Kolekcja regionów projektanta kontrolek dla skojarzonej kontrolki.

Zwraca

String

Znacznik HTML w czasie projektowania skojarzonej kontrolki, w tym wszystkie regiony projektanta kontrolek.

Przykłady

W poniższym przykładzie kodu pokazano, jak utworzyć znaczniki HTML przy użyciu kolekcji DesignerRegionCollection .

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

Uwagi

Host projektu wywołuje metodę GetDesignTimeHtml , aby uzyskać znacznik HTML w czasie projektowania i bieżącą listę regionów projektanta sterowania. Za pomocą kolekcji DesignerRegionCollection host projektu może następnie zażądać narzutu dla każdego edytowalnego regionu projektanta kontrolek.

Metoda GetDesignTimeHtml jest udostępniana dla pochodnego projektanta kontrolek, takiego jak GridViewDesigner klasa, który musi przetworzyć zawartość regionu przed wywołaniem GetDesignTimeHtml metody .

Zobacz też

Dotyczy

GetDesignTimeHtml()

Pobiera znaczniki HTML używane do reprezentowania kontrolki w czasie projektowania.

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

Zwraca

String

Znacznik HTML używany do reprezentowania kontrolki w czasie projektowania.

Przykłady

W poniższym przykładzie kodu pokazano, jak zastąpić metodę GetDesignTimeHtml w niestandardowym projektancie kontrolek. Jeśli właściwość Text skojarzonej kontrolki jest pusta GetDesignTimeHtml , metoda wywołuje metodę GetEmptyDesignTimeHtml . GetDesignTimeHtml W przeciwnym razie metoda tworzy i renderuje kontrolkę Hiperłącze.

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

Uwagi dotyczące dziedziczenia

Jeśli tworzysz niestandardową kontrolkę kontenera, upewnij się, że kontrolka i wszystkie kontrolki podrzędne są renderowane w czasie projektowania, niezależnie od tego, czy Visible właściwość jest ustawiona na true , czy false.

Zobacz też

Dotyczy