Address Capture in ASP.NET

This article describes how to add fast, accurate address capture to your website in under 2 minutes!

To make things simple, we will use the ready-made ASP.NET address capture control which makes using our postcode lookup service very simple. If you haven't already, you will need to download and install these controls. After you've installed them, they will appear on a new Data8 tab in your Visual Studio 2005 toolbox.

Data8 Toolbox

Open the web form you want to add address capture functionality to, and drop on an AddressCapture control.

Address Capture Control

With the control selected, go to the Properties window and set up the Username, Password and Licence properties to your login details for the postcode lookup service.

Address Capture Properties

You can now re-compile your website and you have a fully usable postcode lookup tool! Now you just need to add some code to make use of the address after it has been captured. Add a button to your web form, and in the Click event handler you can access the captured address using the following code:

            protected void Button1_Click(object sender, EventArgs e)
            {
                if (!Page.IsValid)
                    return;
                
                // Save the address to a database as individual lines
                SqlDataSource1.InsertParameters["address1"] = AddressCapture1.Address1;
                SqlDataSource1.InsertParameters["address2"] = AddressCapture1.Address2;
                SqlDataSource1.InsertParameters["address3"] = AddressCapture1.Address3;
                SqlDataSource1.InsertParameters["address4"] = AddressCapture1.Address4;
                SqlDataSource1.InsertParameters["town"] = AddressCapture1.Town;
                SqlDataSource1.InsertParameters["county"] = AddressCapture1.County;
                SqlDataSource1.InsertParameters["postcode"] = AddressCapture1.Postcode;
                SqlDataSource1.Insert();
                
                // Or, save the address as one string value including all the lines
                SqlDataSource1.InsertParameters["address"] = AddressCapture1.FullAddress;
            }
        

Finally, you just need to ensure that your users do complete their address. Just drop a regular RequiredFieldValidator control onto your page, and set up its ControlToValidate property to be the AddressCapture control, and set its ErrorMessage property to a helpful message.

And you're done! By just dragging & dropping the AddressCapture control onto your page and setting up a few properties you can instantly add powerful, fast and accurate postcode lookup and address capture functionality to your web pages.

To deploy your page to a web server, you will need to install the AddressCapture control on the server. If you have full access to the server, you can just run the same installer on the server via Remote Desktop or similar. If you only have shared access to the server, you can copy the Data8.Web.UI.dll file from your development machine (it's usually installed to C:\Program Files\Data8 ltd\Data8 ASP.NET controls) to the bin directory of your website.

Skip Navigation Links
Request handled by server S1 for client 38.107.191.80 at 21/03/2010 14:23:50