Geeks With Blogs

News

Ivan Porto Carrero Placeholder.Add("Really Cool Stuff");

I use guids as PK in my databases.

I like guids :) But The asp.net 2.0 atlas framework shows them as Object and that gives me some trouble using them in my The asp.net 2.0 atlas framework pages.

But to implement your own converter is not so difficult you just inherit from the JavaScriptConverter and override those methods.

And afterwards you have to register it in the converters section of the web.config

The web.config

   21 <microsoft.web>

   22         <converters>

   23             <add type="Microsoft.Web.Script.Serialization.Converters.DataSetConverter"/>

   24             <add type="Microsoft.Web.Script.Serialization.Converters.DataRowConverter"/>

   25             <add type="Microsoft.Web.Script.Serialization.Converters.DataTableConverter"/>

   26             <add type="Flanders.Library.AtlasControls.GuidConverter" />

   27         converters>

 

The Converter Class:

    1 using System;

    2 using Microsoft.Web.Script.Serialization;

    3 

    4 namespace Flanders.Library.AtlasControls

    5 {

    6     public class GuidConverter : JavaScriptConverter

    7     {

    8         public override string Serialize(object o)

    9         {

   10             Guid guid = Guid.Empty;

   11             if(o is Guid)

   12                 guid = (Guid)o;

   13             return "'"+guid.ToString()+"'";

   14         }

   15         protected override string GetClientTypeName(Type serverType)

   16         {

   17             return "Guid";

   18         }

   19         public override object Deserialize(string s, Type t)

   20         {

   21             throw new NotSupportedException();

   22         }

   23         protected override Type[] SupportedTypes

   24         {

   25             get

   26             {

   27                 return new Type[] { typeof(System.Guid) };

   28             }

   29         }

   30     }

   31 }

 

The type in javascript :

Guid = function(){
   this._typeName = 'Guid';
}

 

Posted on Sunday, June 25, 2006 11:31 AM Atlas , .NET 2.0 | Back to top

Copyright © Ivan Porto Carrero | Powered by: GeeksWithBlogs.net