.NET

Building javascript minification into MSBuild scripts

How to use a tool called Packer.NET to build javascript minification into a MSBuild script.
Published in ASP.NET, CSS, Javascript, Tools on Saturday, August 29th, 2009

Restarting an IIS6 app pools using .NET

Two little code snippets for recycling IIS6 application pools in through .NET code.
Published in .NET on Sunday, August 9th, 2009

To(): a handy way to convert strings to other types

The int.parse() method is one I use a lot in ASP.NET so I wrote a handy extension method called To using generic return types and a little reflection that makes converting all these string values to another type incredibly simple.
Published in .NET on Monday, February 23rd, 2009

Improving the way ASP.NET handles 404 requests

How (and why) to make your ASP.NET site's error handling better by returning the right response codes and redirecting to the error page without changing the url.
Published in ASP.NET on Wednesday, February 11th, 2009

Svelte asp.net: avoiding <form runat="server">

postbacks add a lot of weight to your page and you don't always need them. Find out when you can do without them and how to use ASP.NET without paying the postback price.
Published in ASP.NET on Sunday, February 8th, 2009

Opening resx files in the xml editor

Defaults can never please everyone. There’s always someone whose workflow is a little different. That one developer who likes to use SeaMonkey to test their pages or that weirdo who prefers to edit resx files as a text file. I am that weirdo who likes to edit resx files as text files and rather than [...]
Published in Visual Studio on Wednesday, February 4th, 2009

Reducing viewstate on custom controls

One of the biggest waste I see in using viewstate is that it persists values that are already set in the aspx. These get set every time that the page runs and don’t need to be round tripped to the browser so that they will be persisted. I did a little experiment a while back [...]
Published in ASP.NET, Server controls on Sunday, February 1st, 2009

VS2008 SP1 – Microsoft replace my VS with a new one

I just downloaded VS2008 SP1. I just have to wonder what they’re patching that takes 831MB. The installed parts on my harddrive is only 700MB and surely they’re not making me download all the help, bitmaps and tools again? :) At least they have fast servers. :)
Published in .NET on Friday, August 15th, 2008

Saving server control properties to ViewState with custom attributes

Use custom attributes to take the tedious work out of creating server control properties that persist to ViewState. Declare a normal property and use an Attribute to tag it for storage to ViewState. See how to use reflection to see which properties need to be persisted.
Published in Server controls on Wednesday, August 13th, 2008

New ASP.NET server control book for .NET 3.5

Here’s a small plug for Joel who has just released a book on something quite dear to my heart, ASP.NET server controls. It’s called Advanced ASP.NET AJAX Server Controls for .NET Framework 3.5 and looks very interesting. I’m looking forward to adding it to my library. It’ll be nice to have an update to Nikhil’s [...]
Published in Server controls on Thursday, July 10th, 2008

IButtonControl – any button will do

One nice feature of ASP.NET 2.0 is a new interface called IButtonControl. You can use it in a code behind to say a control needs to be a button but without actually saying whether it needs to be a Button, LinkButton, ImageButton or custom control button type. This is the type of thing that’s useful [...]
Published in ASP.NET, Server controls on Monday, June 30th, 2008

Generic method return types

Generics aren't just great for creating lists, they can also be used to return strongly typed information from a method. This example shows how to use a generic return type to parse any type of strongly typed primitive from a string.
Published in .NET on Monday, May 5th, 2008

One more thing to love about .NET generics: events with custom event args

Lists are a killer app for generics in .NET 2.0 but one of my favourite uses that gets less attention is declaring event handlers without having to create a custom delegeate. Imagine a situation where you want to pass a piece of custom information to the event handler so it can decide whether to cancel [...]
Published in .NET on Saturday, April 26th, 2008

Filtering DataView by DateTime

Just a little code snippet to remind me how to do date comparisons in a DataView using DataView.RowFilter. It needs # characters around the date and you seem to need to generate the date string using InvariantCulture: DataTable table = GetList(); table.DefaultView.RowFilter = string.Format("date = #{0}#", DateTime.Today.ToString(CultureInfo.InvariantCulture)); this.GridView1.DataSource = table.DefaultView; this.GridView1.DataBind();
Published in .NET on Saturday, April 5th, 2008

Validating your pages (the technical bit)

So hopefully now you’re convinced that validation is A Good Thing, have decided which doctype you’re going to use and have resolved never to use quirks mode again. Check, check, check. Ok people, that means enough of the talking. We are finally get to the technical stuff: how to validate pages! Validating using the W3C [...]
Published in ASP.NET on Sunday, January 13th, 2008

Friends don’t let friends use quirks mode

Having a doctype in your webpage isn’t just about making your webpage validate. The most important practical reason to include one is to make sure the browsers are rendering in standards compliance mode. Most browsers have two modes for displaying webpages, standards mode and quirks mode. Webpages with a doctype are rendered using standards mode, [...]
Published in ASP.NET on Monday, January 7th, 2008

Choosing a doctype

So making sure that your webpages validate is important because it will make the pages render more consistently across different browsers, meaning you can spend less time debugging cross browser incompatibility and more time with your loved ones/down the pub/plotting world domination. But what are we going to validate against? The current most popular options [...]
Published in ASP.NET on Monday, December 31st, 2007

Sacrificing the validation goat to the browser gods

As a web developer, much of my working day is spent at the mercy of browsers. Sometimes it feels like I spend all my time coaxing useful work from bratty children who don’t like to get along. One of the important tools available for convincing the browsers to play nice is HTML and CSS validation. [...]
Published in ASP.NET on Thursday, December 27th, 2007

Web Standards for ASP.NET developers

Find out more about doing web standards compliant development if you develop in asp.net.
Published in ASP.NET on Thursday, December 27th, 2007

Accessing the contents of a URL through C#

Here’s a quick code snippet for accessing the contents of a url through C#. It’s nice and straight forward. You just need to use the HttpWebRequest and HttpWebResponse System.Net classes to request the url and then a StreamReader to grab the text from the response’s stream. The code should look something like this: HttpWebRequest request [...]
Published in .NET on Sunday, August 19th, 2007

Debug output in stored procedures

I’m a little miffed that you can only debug stored procedures in VS2005 pro and not in VS2005 standard. The frustrating thing is that you can view, edit and trace in VS2005 standard and the menu item for break points is there but it’s greyed out. Pah I say. This little problem led me to [...]
Published in SQL server on Sunday, August 19th, 2007

What type are you really?

I had an interesting problem the other day. I had a situation where someone could pass a type to my method which could be potentially be a nullable type and I needed to know what the real type actually was. It turned out to be pretty easy to find out. The Type type has a [...]
Published in .NET on Friday, May 4th, 2007

Frontpage extensions firewall

I wanted to set up front page extensions on my machine this week so I could access the web projects I wanted by typing in the url rather than having to pick from the list in IIS which is littered with experiments and sample projects. Lazy but worth it considering how often I have to [...]
Published in ASP.NET on Sunday, January 28th, 2007

Using print stylesheets with ASP.NET themes

Using the @media css declaration to create a print stylesheet when you're using ASP.NET themes to automatically include stylesheets.
Published in ASP.NET on Monday, October 16th, 2006

Dynamic sorting for columns that are different data type in a store procedure

I really hate transact SQL. I just want to page some records to display on a webpage and it seems every five minutes I find something new that I have to do in the code to get the thing to work the way I’d expect it to. It just makes me despair. The latest problem [...]
Published in SQL server on Monday, June 12th, 2006