ControlDesigner.GetEmptyDesignTimeHtml Método

Definición

Recupera el formato HTML para presentar un control de servidor web en tiempo de diseño que no tendrá ninguna representación visual en tiempo de ejecución.

protected:
 virtual System::String ^ GetEmptyDesignTimeHtml();
protected virtual string GetEmptyDesignTimeHtml ();
abstract member GetEmptyDesignTimeHtml : unit -> string
override this.GetEmptyDesignTimeHtml : unit -> string
Protected Overridable Function GetEmptyDesignTimeHtml () As String

Devoluciones

Marcado HTML que se usa para presentar un control en tiempo de diseño que, de lo contrario, no tendría ninguna representación visual. El valor predeterminado es un rectángulo que contiene el tipo y el identificador del componente.

Ejemplos

En el ejemplo de código siguiente se muestra cómo invalidar el GetDesignTimeHtml método en un diseñador de controles personalizados. Si la Text propiedad del control asociado está vacía, el GetDesignTimeHtml método llama al GetEmptyDesignTimeHtml método . De lo contrario, el GetDesignTimeHtml método crea y representa un 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

Comentarios

El comportamiento predeterminado del GetEmptyDesignTimeHtml método es devolver una cadena que contiene el nombre del componente. Se GetEmptyDesignTimeHtml debe llamar al método en la implementación del GetDesignTimeHtml método cuando no hay ningún marcado HTML en tiempo de diseño.

Se aplica a

Consulte también