ASP.NET Web Forms: Master Page & CSS File

Mohammed Ali picture Mohammed Ali · Sep 16, 2011 · Viewed 18.6k times · Source

I have a project (Web Application) that I need to implement with Web Forms. I have already prepared the design for the website and I will use one of the CSS templates that I already developed. In this case:

  1. Should I use a master page?
  2. Is there any relationship between the master page and the CSS file? If yes, how should I define master page with the CSS file?

By the way, the CSS file is a ready template.

Answer

Gage picture Gage · Sep 16, 2011
  1. I would highly recommend using a master page. It gives you the ability to have one consistent look across all your pages. Also if you decide to change the layout your only changing one file!

  2. Simply reference the CSS file in your master page and it will be applied to every page the master page is used on. Something like <link href="~/styles/Style.css" rel="stylesheet" type="text/css" />

It should be noted that you can also have more then one master page. Visual studio also allows you to create pages and select the master page, it's one of the other options when adding an item.