Monthly Archives: July 2009

Monthly Archives: July 2009

Show ‘Are you sure you want to navigate away from this page’ message like Hotmail

Posted on by Joe in ASP.NET, JavaScript | 2 Comments

If you start typing an email in Hotmail then navigate away without saving or sending it you get the following message: This is done by using the onbeforeunload window event.  This event can be used to perform any processing needed before navigating to a new page, but if the event handler returns a string you get this confirmation dialog with your own string replacing “You haven’t sent this message. Are you sure you wan’t to discard it?“.  If you press …

ObjectDataSource – Cannot convert value of parameter value from System.String to System.DateTime

Posted on by Joe in ASP.NET, C# | 8 Comments

One bug I’ve come across a few times and again just recently is when using an ObjectDataSource with a GridView to update dates.  When doing the update the ObjectDataSource always uses the en-US culture and not the culture defined for the application. The bug has been acknowledged by Microsoft but never fixed. If you are in the US then you’ll have no problems, but if you are using a culture that uses the dd/MM/yyyy date format such as the UK or Australia you data …

Create a virtual directory in IIS using ASP.NET and C#

Posted on by Joe in ASP.NET, C# | Leave a comment

Update 30th July 2009: After deploying this to a development server there were a few tweaks I needed to make to get it working. I  have amended the post as necessary. I needed to be able to create a virtual directory in IIS via my ASP.NET application.  I found this nice little example in VB.NET and converted it to C#.  You need to add a reference to System.DirectoryServices to use it.  The VB.NET example always puts the new virtual directory in …

How to create a CSV from a DataTable

Posted on by Joe in ASP.NET, C# | Leave a comment

In a project I’ve been working on I came across the need export a DataTable to CSV and this is how I did it.  I have split up the functionality as I also use them to concatenate several DataTables into one CSV. I need to import for following namespaces in this example. The first method gets the DataTable.  It could easily be changed to use stored procedures and add parameters. The next method creates the CSV using a StringBuilder.  First it …

Minimize any application to the System Tray

Posted on by Joe in Misc | 1 Comment

In my current job we use Lotus Notes…… enough said.  Anyway, I wanted it to minimize it to the System Tray as Outlook does but there doesn’t seem to be any option to do this. I came across a freeware application called Tray It! which allows you to minimize any application to the system tray thus relieving much needed task bar space pretty cool!

Linq to SQL Tutorial – ObjectDataSource binding with paging and sorting

Posted on by Joe in C#, Linq | 4 Comments

Update: 31/10/2009 – Added source code ASP.Net has the LinqDataSource which is a handy control but it embeds the business logic in the page which I don’t like. In this post am I going to use the repository objects I created in my last post to bind a GridView using an ObjectDataSource enabling filtering, sorting, and server side paging. I have a GridView control with an ObjectDataSource as the object. Below are the properties for my ObjectDataSource: Here we have …

Linq to SQL Tutorial – Base Repository/Business Logic wrapper

Posted on by Joe in C#, Linq | 2 Comments

Before Linq to SQL I always separated out my Entities, Data Access Layer and Business Logic Layer.  With Linq to SQL it’s a little different as I feel the generated classes are kind of like the Entity and Data Access Layer combined.  Rather than using the generated entities directly it is still good practice to have a Business Logic Layer.  In this example I am using the term Repository which is an aspect of Domain-Driven Design. Each entity will likely need it’s own …

Move wordpress.com blog to other hosting provider

Posted on by Joe in Personal | Leave a comment

Yesterday I moved my blog from wordpress.com to my own hosting provider giving me greater control over my blog. This was quite an easy process but thought I would document the steps I took here incase it helps anyone else. Firstly I installed wordpress on my new host. I then used the Import and Export options in Tools to import all my posts, categories, images etc into my new blog. I then opened up the SQL Admin tool provided by …

Open Flash Chart

Posted on by Joe in Personal | Leave a comment

Open flash chart is on open source project written by my brother-in-law.  It is actually used by WordPress to show the Stats charts. http://teethgrinder.co.uk/open-flash-chart/

Linq to SQL with WCF Services

Posted on by Joe in Linq, Silverlight, WCF | 5 Comments

I was interested to see how I could use Linq to SQL with WCF Services to load and save data using a Silverlight project.  In this post I will expand upon the database I created in my Linq to SQL Tutorial and the console application I wrote for my Set inheritance modifiers with SQLMetal post. The first step is to enable serialisation on my Linq entities so that they can be sent over the wire. To do this in the O/R …