System.Web.UI.WebControls Namespace Style Class
Sets or retrieves the width of a Web control.
Inline |
<asp:control Width = intWidth [ % ]... > |
Script |
Style.Width [ = intWidth ] |
A Unit object that represents the width of the control.
NOTE: Only unit types of pixel and percentage will work.
intWidth |
Integer specifying width, in pixels. |
intWidth% |
Value expressed as a percentage of the parent object's width. |
This property is read/write with no default value.
Exception Type |
Condition |
ArgumentException |
The given width of the Web control was set to a negative value. |
This property specifies the calculated width of the object, in pixels. For table rows and cells, this property has a range of 0 to 32750 pixels.
Percentage values are based on the width of the parent object. If the value of the corresponding HTML attribute was set using a percentage, this property specifies the width in pixels represented by that percentage.
The scripting property is read/write for the Image class, but read-only for other controls.
NOTE: This property is part of the HTML 4.0 standard and as such will only work for browser versions 4 up.
This property will render on downlevel browsers for some controls only. It will not render downlevel for Label, HyperLink, LinkButton, any validator controls, or for CheckBoxList, RadioButtonList and DataList when their RepeatLayout property is Flow.
The following example shows how to declaratively set the Width property of a Web control at design time.
<asp:panel id = "myPanel" runat = "server" width=300 />
The example below shows how to programmatically set the Width property at run time, depending on user input.
void Page_Load ( Object src, EventArgs e ) {
if ( !IsPostBack ) {
for ( int i=100; i<=500; i+=50 ) {
widthSelect.Items.Add ( i.ToString ( ) );
}
widthSelect.SelectedIndex = 2;
}
myTable.Width = int.Parse ( widthSelect.SelectedItem.Text );
}
Show me
Style Members Style.Height Base Web Control Properties