ankitweblogic logo
W e b t u t o r i a l s

Website

ASP.NET Introduction

ASP.NET Web Forms

Standard Controls

Label Control

TextBox Control

Image Control

Button Controls

Redirecting User

Using HyperLinks

RadioButton Control

RadioButtonList

CheckBox Control

CheckBoxList Control

DropDownList

ListBox Control

ImageMap Control

Master Page

View State

Event-Driven Programming

IsPostBack

ASP.NET Page Structure

Visibility of Controls

Formatting Controls

Applying CSS

Dynamic CSS

Using Style Class

Themes and Skins

Panel Control

PlaceHolder Control

AdRotator Control

Calendar Control

Validation Controls

Page Navigation

User Control

Separating Code-Presentation

Overview of ADO.NET

Data Binding

DataBinding List Control

Using Style Class in ASP.NET

The style sheets are actually applied on the client-side. (This is the reason style sheets become ineffective on browsers that do not support JavaScript.)
You can also apply style-sheets on the server-side. ASP.NET provides the Style class (in the System.Drawing namespace) for this purpose. You can create an instance of this class, set its properties, and apply the instance to multiple controls at a time.

Output

The Style class properties are applied to the Label and TextBox controls through the methods, ApplyStyle and MergeStyle. The difference between the two methods is that ApplyStyle overrides the existing properties of the control while MergeStyle does not. Hence, the back color of the Label control changes to blue, while it remains red for the TextBox control.