How to: Set Web Server Control Unit Properties

JavaScript Editor jscript editor     Web designer 



Main Page

Width, height, and similar properties for Web server controls are set in units. Units are implemented as objects (the Unit structure), which allows you to specify a value and the measurement unit in various ways.

To set unit-based properties

  • Assign a reference to the Unit structure to your control.

    The following code examples show variations on how to do this.

    Visual BasicВ CopyCode imageCopy Code
    ' Default is pixels.
    TextBox1.Width = New Unit(100)
    TextBox1.Width = New Unit(100, UnitType.Pixel)
    TextBox1.Width = New Unit("100px")
    ' Centimeters.
    TextBox1.Width = New Unit("2cm")
    TextBox1.Width = New Unit(10, UnitType.Percentage)
    TextBox1.Width = New Unit("10%")
    
    C#В CopyCode imageCopy Code
    // Default is pixels.
    TextBox1.Width = new Unit(100);
    TextBox1.Width = new Unit(100, UnitType.Pixel);
    TextBox1.Width = new Unit("100px");
    // Centimeters
    TextBox1.Width = new Unit("2cm");
    TextBox1.Width = new Unit(10, UnitType.Percentage);
    TextBox1.Width = new Unit("10%");
    

See Also

Tasks

How to: Set ASP.NET Server Control Properties (Visual Studio)

Other Resources

Setting Web Server Control Properties Programmatically (Visual Studio)



JavaScript Editor jscript editor     Web designer