I’ve just finished building an FAQ section for one of Storm’s clients. The client requested that a list of questions be shown at the top of the page and the user be scrolled to the appropriate answer when they clicked the question. The site was using a URL re-writing scheme that meant using traditional #anchor links was impossible. We got around this by using a very simple piece of JavaScript.
Scroll an element into view programmatically with JavaScript
June 14th, 2010 | by Adam Pope | No CommentsTagged in: JavaScript JQuery Tutorials
Prevent a C# or VB.NET Console Application from closing when it finishes
June 8th, 2010 | by Adam Pope | 4 CommentsI’m working on a little console application to run a scheduled data import task. During the debugging of the application I wanted the console window to remain open after the program had finished executing – by default it closes when the application finishes. There seem to be two common answers to this problem.
Tagged in: C# Visual Studio
URL Re-Writing in ASP.NET Requires Form Action to be Re-written
June 4th, 2010 | by Adam Pope | 1 CommentOn a project I was working on recently we ran into a problem where the combination of URL re-writing and postbacks caused the page to post back to the wrong URL. When you create an ASP.NET page with a <form runat=”server”> tag, ASP.NET will automatically output the action attribute to be the URL of the current page. However, the URL that is used is not the original URL of the request, but instead the real URL of the page. For example, when you are on the page “/services/web-design” the real request might be to “/services.aspx?service=web-design”. When you do a postback, you will be returned to the ugly URL.
Execute JavaScript when an UpdatePanel is updated
June 4th, 2010 | by Adam Pope | 2 CommentsI’ve just spent a few hours banging my head against a wall trying to get ASP.NET to execute a JavaScript function each time an UpdatePanel is updated. Simply putting the script within the ContentTemplate tags does not work. Instead, to get the JavaScript to execute on PostBack you need to use ScriptManager.RegisterStartupScript to register the script to be run.
Tagged in: ASP.NET ASP.NET AJAX JavaScript
Using SQLite with NHibernate for Unit Testing
May 26th, 2010 | by Adam Pope | No Comments
Fast, automated unit testing is a vital component of any development project. At Storm we use NUnit with TestDriven.NET from within Visual Studio to run our test suites as we develop. We also use NHibernate with SQL Server for the data access layer of our applications. To ensure each of our unit tests is atomic it is necessary to setup and teardown a new copy of the database for each test or series of tests. With an SQL Server instance of a seperate box, this can be painfully slow once your test library reaches even a moderate size. To speed things up, we’ve moved to in-memory SQLite. Here’s how!
Tagged in: NHibernate SQLite Tutorials Unit Testing
Sending email with GMail’s SMTP server in ASP.NET
May 18th, 2010 | by Adam Pope | 7 CommentsSending email via SMTP in ASP.NET is a really painless experience. However, there are a couple of hoops to jump through if you want to use Google’s GMail SMTP servers. The example in this post shows a really simple function to get the job done.
The Haversine Formula in C# and SQL: Distance between two points
May 17th, 2010 | by Adam Pope | 1 CommentStorm was recently asked to create a local office finder for a client. We used the Google Maps API to geo-locate the offices, storing their lat/lng co-ordinates in a database. Each time a customer performs a search for their town or post code we use the same process to their lat/lng co-ordinates as well. Now we have the information we need, but how you find out which offices is closest to the customer? We use the Haversine Formula.
Tagged in: C# Code Geolocation Tutorials
Using the Google Maps API to get long/lat co-ordinates from a postcode or address
May 17th, 2010 | by Adam Pope | 3 CommentsStorm were recently asked to create a local office finder for franchised business VoIP provider, Datasharp. The client requested that the user should be able to enter their postcode or town/city and be informed where their nearest branch was. To make this possible we would need the latitude and longitude co-ordinates for each office and the customer, but how do you get the co-ordinates from the address?
Tagged in: C# Code Geolocation Tutorials
Convert an angle in Degrees to Radians in C#
May 17th, 2010 | by Adam Pope | No CommentsI was recently using Google Maps API geo-location lookups to get the longitude and latitude of an address entered by the user. I wanted to find the distance between a two co-ordinates using the Haversine Formula. To do this I needed to convert my lat/lng co-ordinates into radians. This seemed like an excellent opportunity to create a new extension method to add to Storm’s library of re-usable code.
Generic HashTable in C#
February 12th, 2009 | by Adam Pope | No CommentsI had a bit of a brain fail earlier and couldn’t remember how to create a <strong>HashTable</strong> with generic type arguments. There was a Hashtable and a HashSet<> but neither were what I was looking for.
Tagged in: C#





