Muokkaa

Jaa


ControlDesigner.GetDesignTimeHtml Method

Definition

Retrieves the HTML markup that is used to represent the control at design time.

Overloads

GetDesignTimeHtml(DesignerRegionCollection)

Retrieves the HTML markup to display the control and populates the collection with the current control designer regions.

GetDesignTimeHtml()

Retrieves the HTML markup that is used to represent the control at design time.

GetDesignTimeHtml(DesignerRegionCollection)

Retrieves the HTML markup to display the control and populates the collection with the current control designer regions.

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

Parameters

regions
DesignerRegionCollection

A collection of control designer regions for the associated control.

Returns

The design-time HTML markup for the associated control, including all control designer regions.

Examples

The following code example shows how to create HTML markup using the DesignerRegionCollection collection.

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

Remarks

The design host calls the GetDesignTimeHtml method to get the design-time HTML markup and the current list of control designer regions. Using the DesignerRegionCollection, the design host can then request the markup for each editable control designer region.

The GetDesignTimeHtml method is provided for a derived control designer, such as the GridViewDesigner class, that must process the content for the region before calling the GetDesignTimeHtml method.

See also

Applies to

GetDesignTimeHtml()

Retrieves the HTML markup that is used to represent the control at design time.

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

Returns

The HTML markup used to represent the control at design time.

Examples

The following code example demonstrates how to override the GetDesignTimeHtml method in a custom control designer. If the Text property for the associated control is empty, the GetDesignTimeHtml method calls the GetEmptyDesignTimeHtml method. Otherwise, the GetDesignTimeHtml method creates and renders a Hyperlink control.

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

Notes to Inheritors

If you are creating a custom container control, make sure that you render the control and all child controls at design time, regardless of whether the Visible property is set to true or false.

See also

Applies to