Condividi tramite


WebControl.Width Proprietà

Definizione

Ottiene o imposta la larghezza del controllo server 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

Valore della proprietà

Oggetto Unit che rappresenta la larghezza del controllo. Il valore predefinito è Empty.

Attributi

Eccezioni

La larghezza del controllo server Web è stata impostata su un valore negativo.

Esempio

Nell'esempio seguente viene illustrato come impostare in modo dichiarativo la Width proprietà del Table controllo, ereditata dalla WebControl classe 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>

Commenti

Utilizzare la Width proprietà per specificare la larghezza del controllo server Web.

Annotazioni

Questa proprietà non esegue il rendering per tutti i controlli nei browser precedenti a Microsoft Internet Explorer versione 4. I controlli che non eseguono il rendering di questa proprietà nei browser precedenti includono Label, HyperLinkLinkButton, e tutti i controlli di convalida. E inoltre non esegue il CheckBoxListrendering di questa proprietà nei browser precedenti quando la proprietà RepeatLayout è impostata su RepeatLayout.Flow.DataListRadioButtonList Inoltre, solo i tipi di unità di Pixel e Percentage sono supportati nei browser precedenti.

Poiché questa proprietà non è html standard, i controlli server Web visualizzati come tabella, ad esempio Table e DataGrid, non supportano questa proprietà nei browser precedenti a Microsoft Internet Explorer versione 4.

Annotazioni

Per impostare la Width proprietà in modo dichiarativo su un tipo di unità diverso dall'impostazione predefinita di Pixel, è necessario creare un nuovo tipo di unità specifico per il tipo di unità desiderato. Ad esempio, per impostare la proprietà di Width un controllo su un valore percentuale pari a 100, è possibile eseguire le operazioni seguenti:

myWebControl.width = Unit.Percentage(100);

Per altre informazioni sui tipi di unità disponibili per la Width proprietà, vedere la Unit classe .

Si applica a

Vedi anche