Archives

Archives / 2008 / April
  • ASP.NET MVC CSS Sprite

    A month ago, I wrote about my technique to output a CSS sprite for ASP.NET. Granted, I made a big mistake. I put WAY too much bloat into the post. Not a K.I.S.S. moment.

    I have reworked my CSS sprite technique to be unique to MVC. I've used the most recent build of the MVC framework, which can be downloaded on Codeplex, to take advantage of ActionResult. What the ActionResult does is makes your controllers more testable and makes the execution of the controller more specific. Instead of a void, controllers now return an ActionResult (see Scott Guthrie's post on the interim release).

    I have a download, see the bottom of the post, that includes a sample application and a class library that you can distribute with any MVC application. The sample pulls 2 images off the Internet, plugs them into a sprite through the Sprite controller.

    image

     

    What you get when you execute the Sprite controller is a sprite that looks like so:

    image

     

    What you do in your CSS file is reference the sprite URL and specify the background-position, width, and height.

    image

     

    Then with the following HTML:

    image

    you get the images separate from the sprite.

    image

    What you get is an easy-to-use API for sprite generation and faster-loading website (less HTTP requests per page) using sprites instead of multiple images. If you want all of the CSS editing to happen at runtime, see my original post of CSS Sprites for that code.

    DOWNLOAD SAMPLE APPLICATION AND CODE




    kick it on DotNetKicks.com

  • Source Code conversion as part of a Build Process

    If you're like me, you want a particular piece of code in your particular language. For example, a lot of people want the Club Starter Kit 2.0, 3.0 in C# since it has been written in VB. Me being the lazy open source developer that doesn't get paid :), I keep delaying the CSK conversion to C# because of my personal stuff. Then I was thinking, what if it were a part of the build process? Then I wouldn't have to go through the arbitrary process of converting a whole application to another language for a release that I will most likely be changing.