When developing ASP.NET websites (using VB.NET web forms) – a lot of my time is spend writing CSS files and they always seem to get messy (code duplication) and very long.
All I want to achieve is to be able to manipulate the CSS using VB.NET code in the following ways:
- Use an integer variable to store my “golden” number 7 and use that for width, padding, margin etc where needed
- Use string variables to store my “golden” hex color codes e.g. “#44C5F2” and use them for color, background-color, border-color etc. where needed
- Use an integer variable to set the height of an element and have four child elements each with height: mynum / 4
I just want to use basic VB.net number and string manipulation in order to create a CSS file on the fly.
I understand that the end product – the CSS file shouldn’t change much – it should at most change on a daily basis otherwise caching couldn’t be used.
I also understand that I would lose Visual Studio CSS intellisense support but…
How do I achieve this?
Should I be using:
- Generic handlers (ASHX)
- ASP.NET Themes
- ASP.NET Skins
- Something else?
I just some pointers.
Any help is appreciated.
Thanks.
I decided to go with a WebHandler (ASHX file) in the end:
CssOnTheFly.ashx
CssOnTheFly.ashx.cs
Because I could create bespoke classes to generate CSS on the fly – so I have more flexibility.
I think I need to use C# for this because VB.NET doesn’t really have multi-line string literals.