Asp. NET Hands-on Tutorial 5

Source: Internet
Author: User
Tags control label extend html tags advantage
Asp.net| Tutorial Apply styles to HTML server controls
Web is a flexible user interface environment, different sites in the visual and sensory changes in the way. Cascading styles
Table (CSS) is widely used, which greatly enriches the design of the web. All asp.net HTML server controls and Web suits
Service control, has been designed to provide first-class CSS style support. This section discusses how to apply styles to services
Control, and demonstrates the finer appearance control that server controls provide in Web Forms.
Apply styles to HTML server controls
Standard HTML tags use the Style property to support the Css,style property by a series of pairs that appear semicolon-separated
Attribute/value to define. For example {font:12pt verdana; font-weight:700;color:orange;}. About I
e Browser For more information on CSS property support, refer to the MSDN Web workshop CSS Attributes refer
ence page. All asp.net HTML server controls can accept CSS styles like standard HTML flags
。 The following examples illustrate the application of some styles to different HTML server controls. If you look back to the client
Source, you will find that the styles referenced in the control are delivered to the client.
C # style1.aspx
[Run] | [Source program]
CSS also defines the class attribute and sets CSS styles by including them in the document. This genus
The advantage of sex is that you need to define it only once, and you can apply it to different labels without having to redefine the label itself
Style. The style of HTML server controls can also be managed in this way. Take a look at the following example:
C # style2.aspx
[Run] | [Source program]
When the ASP.net page is parsed, the style information is assembled into the System.Web.UI.HtmlControls.Html
The Style property on the control class (type is CssStyleCollection). This property creates a dictionary to Word
The values in the collection of string indexes that populate each style property value of the applied control style. For example, you can use the following
Code to set and retrieve the width style property value of the HtmlInputText server control.

The following example shows you how to use the Style collection properties to manipulate HTML server controls like
Expression
C # style3.aspx
[Run] | [Source program]
Apply styles to Web server controls
Web server controls provide an additional level of support for styles that add several strong types for commonly used style settings
Property. Common styles include background color, foreground color, font name and size, width, font aggravation, and so on. These kind of
property as a subset of the style behavior that can be used in HTML, and as a "platform" property, the SYSTEM.WEB.U
I.webcontrols.webcontrol directly in the base class. The advantage of using these properties is that in development tools, examples
As in Vs.net, they provide compile-time type checking and state completion.
The following example shows a calendar control that has a number of styles applied (as a control, while containing an unused
The calendar control for the style. Note that when you set a property of a class type, such as font, you need to use the child attribute syntax
Property name-child property name.
C # style4.aspx
[Run] | [Source program]
Namespace System.Web.UI.WebControls contains a style base class that encapsulates commonly used style attributes (other
Style classes, such as TableStyle and TableItemStyle, are inherited from this base class.
Many server controls extend this type of property to specify the style of the branch element of the control. For example, Calendar control
The pieces extend a number of style attributes: DayStyle, WeekendDayStyle, TodayDayStyle, Selecteddaysty
Le, OtherMonthDayStyle, and NextPrevStyle and so on. You can use the Child attribute syntax property name-Child
Property names to set the branching properties of these styles, as in the following example:
C # style5.aspx
[Run] | [Source program]
A subtle differential syntax that allows you to declare each style property as a child element nested in the Web server control label
In
Backcolor= "Olivedrab" height= "50px"/>
The following example shows the alternating display syntax, but functionally the same as the previous one.
C # style6.aspx
[Run] | [Source program]
As with HTML server controls, you can use CSS class definitions to apply styles to Web server controls. Webc
The Ontrol base class extends a string property named CssClass, which is used to set the style class:
C # style7.aspx
[Run] | [Source program]
If the property set to the server control does not conform to any of the strongly typed properties of the control, the property and value are
Into the attributes collection of the control. By default, server controls will refer to these genera without modification
Sex is returned to the requesting browser client. This means that the properties of styles and classes can be applied directly to the server
control, rather than using the strongly typed properties of these controls. Of course, knowing this concept requires understanding the actual reference of the control
, he is also a flexible way of applying styles. This method is especially useful for standard form input controls.
Take a look at the following example:
C # style8.aspx
[Run] | [Source program]
By using the ApplyStyle method of the WebControl base class, the style of the Web server control can also be set by the program,
Like the following code:
Login:/
Password:
View: ...
The following example shows the above code
C # style9.aspx
[Run] | [Source program]
section of this chapter:
1. ASP. NET's HTML server controls and the WEB server control family provide Best-in-class CSS style support.
2. You can apply styles by setting the style or class properties of the control. These settings can be passed by the attribute of the control
The S collection is accessed using programs. For HTML server controls, the branch value of a style property can be passed through the control's style collection
To get.
3. Most commonly used style settings are already strong-typed properties of the Web server control itself
4. The System.Web.UI.WebControls namespace contains a style base class that encapsulates the commonly used type attributes. Many
The WEB server control extends this property as a branching reference element.
5. For server controls, the ApplyStyle method using the WebControl base class can use programs to set styles.
asp.net Chinese professional network wincheer translation .... Cond.........


Related Article

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.