Asp.net Server Control property settings

Source: Internet
Author: User

As a mark, attribute settings will be frequently used in the future.

You can set web server control properties by programming to change the control's appearance and behavior at runtime.

The following describes how to set different attribute types:

1. Set Properties Based on Single value or enumeration:
If the data type of the Web server control property is basic (string, Boolean, or numeric), you only need to specify it to the property to set the corresponding property value. Similarly, if the attribute value is defined in the enumeration class, you can only specify this enumeration to the attribute.

1.1 set single-value-based Attribute values 

■ Specify this value as a text or variable, as shown in the following example:

Label1.text = "hello ";
Datagrid1.pagesize = 5;

■Set enumeration-based Attribute values 

// Uses textboxmode Enumeration
This. textbox1.textmode = textboxmode. singleline;
// Uses imagealign Enumeration
This. image1.imagealign = imagealign. Middle;

2. Set Unit attributes:
The width, height, and similarity attributes are set in units. The Unit is implemented as an object (unit structure). You can specify the value and measurement unit in multiple ways.
2.1Set unit-based attributes 

// Default is pixels.
Textbox1.width = new unit (100 );
Textbox1.width = new unit (100, unittype. pixel );
Textbox1.width = new unit ("100px ");
// Centimeters
Textbox1.width = new units ("2 cm ");
Textbox1.width = new Unit (10, unittype. Percentage );
Textbox1.width = new units ("10% ");

3. Set the color attribute
To set the color (for exampleBackcolorAttribute.ColorObject reference.

Button1.backcolor = color. fromname ("red ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.