WebControl.Width Propiedad

Definición

Obtiene o establece el ancho del control de servidor web.

public:
 virtual property System::Web::UI::WebControls::Unit Width { System::Web::UI::WebControls::Unit get(); void set(System::Web::UI::WebControls::Unit value); };
[System.ComponentModel.Bindable(true)]
public virtual System.Web.UI.WebControls.Unit Width { get; set; }
public virtual System.Web.UI.WebControls.Unit Width { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Width : System.Web.UI.WebControls.Unit with get, set
member this.Width : System.Web.UI.WebControls.Unit with get, set
Public Overridable Property Width As Unit

Valor de propiedad

Un elemento Unit que representa el ancho del control. De manera predeterminada, es Empty.

Atributos

Excepciones

El ancho del control de servidor Web se ha establecido en un valor negativo.

Ejemplos

En el ejemplo siguiente se muestra cómo establecer mediante declaración la Width propiedad del Table control, heredada de la WebControl clase base.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>WebControl Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Width Property of a Web Control</h3>
    <asp:Table id="Table1" runat="server"
        CellPadding="10" GridLines="Both"
        Width="350">
 
        <asp:TableRow>
            <asp:TableCell>
                Row 0, Col 0
            </asp:TableCell>
 
            <asp:TableCell>
                Row 0, Col 1
            </asp:TableCell>
        </asp:TableRow>
 
        <asp:TableRow>
            <asp:TableCell>
                Row 1, Col 0
            </asp:TableCell>
 
            <asp:TableCell>
                Row 1, Col 1
            </asp:TableCell>
        </asp:TableRow>
 
 </asp:Table>
 
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>WebControl Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Width Property of a Web Control</h3>
    <asp:Table id="Table1" runat="server"
        CellPadding="10" GridLines="Both"
        Width="350">
 
        <asp:TableRow>
            <asp:TableCell>
                Row 0, Col 0
            </asp:TableCell>
 
            <asp:TableCell>
                Row 0, Col 1
            </asp:TableCell>
        </asp:TableRow>
 
        <asp:TableRow>
            <asp:TableCell>
                Row 1, Col 0
            </asp:TableCell>
 
            <asp:TableCell>
                Row 1, Col 1
            </asp:TableCell>
        </asp:TableRow>
 
 </asp:Table>
 
    </div>
    </form>
</body>
</html>

Comentarios

Utilice la Width propiedad para especificar el ancho del control de servidor web.

Nota

Esta propiedad no se representa para todos los controles de exploradores anteriores a Microsoft Internet Explorer versión 4. Los controles que no representan esta propiedad en exploradores anteriores incluyen Label, LinkButtonHyperLink, y los controles de validación. RadioButtonListDataList y CheckBoxListtampoco representan esta propiedad en exploradores anteriores cuando su RepeatLayout propiedad está establecida RepeatLayout.Flowen . Además, solo se admiten tipos de unidad de Pixel y Percentage en exploradores anteriores.

Dado que esta propiedad es HTML no estándar, los controles de servidor web que se muestran como una tabla, como Table y DataGrid, no admiten esta propiedad en exploradores anteriores a Microsoft Internet Explorer versión 4.

Nota

Para establecer la Width propiedad mediante declaración en un tipo de unidad distinto del valor predeterminado de , debe crear un nuevo tipo de Pixelunidad específico para el tipo de unidad que desee. Por ejemplo, para establecer la propiedad de Width un control en un valor de porcentaje de 100, puede hacer lo siguiente:

myWebControl.width = Unit.Percentage(100);

Para obtener más información sobre los tipos de unidad disponibles para la Width propiedad , vea la Unit clase .

Se aplica a

Consulte también