Apply Style to Every Control on Website in ASP.NET


I guess you are expert in styling controls using CSS. But the thing I am going to talk in this post is bit different. Let's look at following asks:

(i) How to apply style to all Label controls on website?
(ii) How to apply TextBox background color or font color (ForeColor) to all controls on websites?
(iii) How to apply style to all Hyperlink controls on website?

To answer these all question let's read this.

Follow the steps:-

Step 1

Create a style sheet page by name 'SiteStyle.css' and save this under project root.

Step 2

Type following style information in SiteStyle.css page:


Please note: I am using span, input and a. span is HTML markup of Label control in ASP.NET and input is HTML markup of TextBox and a is HTML markup of Hyperlink.

Step 3

Place the reference of the style sheet file in head section of web pages where you wish to apply this style. If you are using master page then it's pretty easy just place only there in the head section. Here is the code that you need to place.

    <link href="SiteStyle.css" rel="stylesheet" type="text/css" />

Step 4

Now all we set to test, let's create any hyperlink or textbox or label on web page see it in action.
I will recommend you to download the sample project attached here to test. I hope you like it. Thanks.


Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples