ASP.NET News from Blogger: K. Scott Allen   Get the feed of: K. Scott Allen

Total News: 521

Programming Windows 8: The Sublime To The Strange

Microsoft unveiled Windows 8 at the //build/ conference in September. Since then I've spent time seeing how to put together Windows 8 metro applications with HTML and JavaScript. The Sublime The fo...

Getting Intrinsic HTML5 Video Dimensions

The HTML 5 DOM interface for a video element allows you to get the underlying video's width and height in pixels, but, be careful not to ask for the dimensions too early. If you ask as soon as the DOM...

Composing Entity Framework Fluent Configurations

The canonical example for fluent configuration with the Entity Framework is to take a few simple entity definitions: public class Product { public int Id { get; set; } public string Name { ge...

Modernizr.js: Polyfills

In the last post we looked at feature detection with Modernizr. Before moving forward, let me answer a few questions that came up. First, you can build a custom Modernizr download containing only th...

Architectural Tragedy of the Commons

From Wikipedia: The tragedy of the commons is a dilemma arising from the situation in which multiple individuals, acting independently and rationally consulting their own self-interest, will ...

Modernizr.js : Feature Detection

As we saw in a previous post, Modernizr allows you to work with the new HTML 5 elements, like nav, and still support browsers that don't know anything about a nav, or HTML 5. However, HTML 5 is more...

Modernizr.js

Modernizr.js is a little library that will help "modernize" old browsers. As an example, let's say you create a new ASP.NET MVC 3 application with the "Use HTML 5 semantic markup" checkbox selec...

Rise and Fall of Classic OOP

When I was making the switch from C and assembly to C++ I did quite a bit of reading on object oriented programming. It's hard to find material on OOP that doesn't praise the classical pillars of enca...

Execute<T> With IronRuby

Imagine (or dream) that you have some IronRuby code to execute. require 'net/telnet' host = Net::Telnet.new(:Host => 'localhost') #... #... #... return data One way to execute the code and c...

C# Fundamentals Part II & 10 Rules for Better C# Code

The second part of my C# fundamentals course is available for subscribers on Pluralsight.com. Part 2 introduces you to the variety of programming styles supported by the C# language. At its core,...

CSS Tricks and the Alternate Universe of Graphics Primitives

Someone asked about the circular div I used for magnification in an earlier post. There are no primitives in CSS for building arbitrary shapes, but like most things on the web, that doesn't stop anyon...

A Magnifying Lens using Script and CSS

Magno is a something I put together because well, just because. The idea is to provide a magnifying lens effect using a background image and background position animation. The lens tracks the positio...

A Simple 2-Column Layout in Razor

2 column layouts are rather popular on the web, and there are 1,001 ways to make them work. The approach you choose really depends on the type of content you have, and how you want images and backgrou...

A Tale of Backgrounds, Absolutes, mouseleave, and mouseenter

mouseleave is simple to understand: Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element. How hard could it be? http://jsfiddle.net/JP6aV/ $...

Underscore.js

Liam told me about Underscore.js some time ago. From the home page: Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would exp...

Clojure and the CLR

From the Clojure home page: Clojure is a dialect of Lisp, and shares with Lisp the code-as-data philosophy and a powerful macro system. Clojure is predominantly a functional programming language, ...

What's Wrong With This Code? (#28)

Victor Brumble is writing code again, and this time he's writing a jQuery plugin. His plugin makes alert boxes easy, because Victor loves pointless, model dialogs. (function ($) { var settings ...

Disabling jQuery UI Widgets

It's easy to make a DOM element draggable and droppable with jQuery, but it's not as obvious how to make it stop. It turns out every widget includes a set of standard methods, and one of the standard ...

Use a ReSharper Template for Script Files

Using Alt+Ins in the Solution Explorer window is one of those ReSharper shortcuts that probably saves me hours over the course of a year (Alt+Ins is the "Create File From Template" command). There i...

Manual Validation with Data Annotations

Several people have asked me about using data annotations for validation outside of a UI framework, like ASP.NET MVC or Silverlight. The System.ComponentModel.DataAnnotations assembly contains everyth...

A Better Razor IsNullOrEmpty Statement

This post is a play on Phil's "A Better Razor Foreach Loop". If you aren't familiar with templated delegates in Razor, you can follow the links in Phil's post. Something I don't like to see in a v...

The Developer's Workplace

workplace [n] - a place where work is done Over the years I've worked with developers in cubicle farms and private offices, in open spaces and cloistered bureaus. And once there was a basement room a...

Lazy Exceptions for Fake LINQ Queries

If you want to simulate an exception from an IQueryable data source, be careful about when the exception is thrown. As an example, let's use the following interface. public interface IContext { ...

Faking DbContext

I like Kzu's take on building unit-testable domain models with EF code first. I've been playing around with some of the same ideas myself, which center around simple context abstractions. public int...

DynamicModuleUtility

One of the interesting side-effects of installing ASP.NET MVC 3 is the appearance of Microsoft.Web.Infrastructure in the GAC. Inside the assembly is a DynamicModuleUtility class that will let you do t...

Custom Data Annotation Validator Part III: QUnit Tests

QUnit is an easy to use testing framework* for an easy to test language. Once you've downloaded the library you can load up an .html page with all of your scripts, and the boilerplate qUnit HTML: &l...

Custom Data Annotation Validator Part II: Client Code

The validator we looked at in the last post only supports server side validation. To support client side validation we need a little more code on the server, and some custom client script. One appro...

Custom Data Annotation Validator Part I : Server Code

Let's say you want to create a GreaterThan validation attribute and use it like so: public class Trip { [Required] public DateTime StartDate { get; set; } [Required] [Gr...

Html.Awkward

Ive seen the HTML helpers in ASP.NET MVC drive developers to madness. For example: @Html.ActionLink("Detail", "Detail", "Car", new { id = 5 }) ... produces ... <a href="/Home/Detail?Lengt...

Notes on Building Razor Views

Just like web form views, razor views dont build when you build an MVC project in Visual Studio. By default, the parsing and compilation of a view doesnt happen until runtime, meaning you might not kn...

Revisiting Charts: HTML5 Attributes

The charting sample I wrote years ago rendered image tags like this: <img id="topDestinations" src="roller.gif" /> The roller gif was a spinning animation that let the user know some work...

Revisiting Charting with ASP.NET and LINQ

Once upon a time I wrote an article titled Charting with ASP.NET and LINQ. At the time I used a combination of WebForms, WCF, the Microsoft AJAX libraries, and the Microsoft chart control. I had some ...

Stackoverflow Exceptions with Html.Action

If you ever have a stack overflow using Html.Action or Html.RenderAction in a Layout view, then check the return type of your child action. public class Weather : Controller { public ActionResu...

Once More In Defense Of The var Keyword

Even today there are those of you who doubt the power of the var keyword in C#! Or rather, there are those of you who steadfastly refuse to use it. I think the var keyword provides a nice symmetry f...

The Value of Symmetry

Symmetry in code is valuable, and often subtle. When I find symmetry in code, I feel it's a positive sign that the design is working well. I like temporal symmetry. When something opens at the very ...

If Software Was Like The Super Bowl

We'd have cheerleaders, fans, and of course . . . reporters to write about it all. V-TPS Team Defeats Milestone 6 in Overtime Ken Hoethlisberger came out of the project war room with a huge smile a...

Make It Yours

I went to a general store, but they wouldn't let me buy anything specific. - Steven Wright. One of the challenges of working with a general purpose programming language (like C#) and a general purpo...

JavaScript Koans

Programming koans liberally borrow from Zen Buddhism to teach programming. If you look around the Internet, you'll find koans to learn Ruby, koans to learn functional programming, and thanks to Liam M...

Great Engineering Quotes

Charles F. Kettering was an engineer, founder of Delco, and the head of research at General Motors for 27 years. I ran across a few choice quotes from the man. A problem well stated is a problem hal...

The Big Rewrite

Unlike refactoring, a "big code rewrite" bulldozes an entire application and starts over from scratch. Is it ever the right thing to do? In a recent post, Steve Blank says no - never for start u...

It's Design

If I come across this code: if (widget.Price < 10.0m && widget.UnitsInStock > 100) { // ... } Then the first thing I'll suggest is refactoring to: if (widget.IsElig...

The Refactoring Curve

Empirical studies on software refactoring are hard to find, but I believe refactoring follows the 80/20 rule - 80% of the possible benefit comes by applying just the first 20% of effort. Like most wor...

What’s Wrong With This Code? (#26)

A measurement consists of a high reading and a low reading, but the high and low values are optional. We also need to add measurements together, so the following C# code: var m1 = new Measurement(low...

Injectable, Configurable Action Filters

One of the advantages to using a custom IFilterProvider is how you gain total control over the instantiation of action filters in ASP.NET MVC 3. When you combine an IoC container with a filter provide...

Configurable Action Filter Provider

In MVC 3 you can implement an IFilterProvider to create and feed action filters to the MVC runtime. Assuming you have the configuration classes in place from the last post, you can create a custom fil...

Configurable Global Action Filters for ASP.NET MVC

ASP.NET MVC 3.0 introduces global action filters - an easy way to apply an action filter to every action in an MVC application. All you need to do is register the filters during application startup: ...

HTTP Modules versus ASP.NET MVC Action Filters

ASP.NET MVC has action filters, while ASP.NET has HTTP modules. Inside their respective processing pipelines, these abstractions serve similar purposes, and I've heard the following question a few t...

Razor Tip #2 : Inheritance & Configuration

You can change the base class of a Razor view in ASP.NET MVC using an @inherits directive. @inherits MyWebViewPage<dynamic> The default base class for a Razor view in ASP.NET MVC is WebViewPag...

MonoDroid Preview

MonoDroid allows you to write Android applications using C# and Visual Studio. Compare the code in the last post to the following: [Activity(Label = "My Activity", MainLauncher = true)] public cl...

IntelliJ IDEA for Android Development

I really like IntelliJ IDEA - and the free community edition now supports Google Android development. Part of the reason I like this IDE is because it feels familiar. I've learned the JetBrains sense...

View Other bloggers