I’ve been working with the ASP.NET AJAX Extensions a lot lately, and have been learning a few trick on how to get stuff done. One of the things I’ve learned is how to create a Generic TypeConverter for ASP.NET Ajax to use when serializing my server-side objects to JSON when passing them down to the client-side. **Introduction**
When creating an ASP.NET Extender Control (using ASP.NET AJAX and the AJAX Toolkit) you can add custom properties to your Extender (using the ExtenderControlProperty attribute) that get passed down to the client. Well, this is really cool and all, but you are restricted to using the “standard” variable types (string, int, bool, etc.); unless of course you want to create your own custom TypeConverter to convert your custom objects to JSON. **How do I create and use a JSON TypeConverter?**
and, do I need to create a separate one for each of my “custom” objects? First off, it’s pretty simple, and secondly, you can create “generic” TypeConverter that will work with virtually all your objects.
**Step 1: **Create a new Extender Control (http://ajax.asp.net/ajaxtoolkit/Walkthrough/CreatingNewExtender.aspx)
Even though this ends up being a very simple thing to do, it took me a lot of time (a few months ago) to figure out since there aren’t very many articles out there on how to do stuff with ASP.NET AJAX.
I also kept this article pretty simplistic, since I’m offering the complete solution for download and code always speaks for itself.
**Download Sample Code: **CustomJSONTypeConverter.zip
This blog post is licensed under the Creative Commons Attribution 3.0 United States License, unless explicitly stated otherwise within the blog post content. All other content on this website is not licensed under Creative Commons licensing.