Archive for the CC’s Friends Category

Persisting Custom Control Properties in C# 2.0

Posted in Asp.Net, C#, CC's Friends on October 30, 2006 by Shaun

I recently found myself in a bit of a pickle trying to persist some properties in a custom control I am developing at work.  My confusion was down to several properties persisting fine while other properties just would not maintain any values when I switched between source and design views in my test application.
I was ready to throw in the towel and put this down to a quirk with ASP.Net Custom Controls and try out some really complicated method to force the properties to persist when I stumbled upon something interesting.

If I set my property to be a string everything persisted, with no extra effort on my part for example:

public string Foo
{
...
}

works fine, while:

public double Foo
{
...
}

won’t persist.  A bit of research led me to believe that the .net framework takes care of strings for you.
I then noticed that all the properties I had that were not strings but were persisting just fine had a typeConverter applied to them, either custom converters I had written, or converter from the .Net framework.
for example:

[typeConverter(typeOf(ColorConverter))]
public colour Foo
{
...
}

worked just fine… so I tried the following with the double sample above:

[typeConverter(typeOf(DoubleConverter))]
public double Foo
{
...
}

This resulted in the property persisting fine.

So, the reason for this post is two fold really, it may provide a clue to anyone else struggling to persist their properties as I was, but also it opens this up for comment as to whether this is the right way of going about this or whether there is indeed a better way.
Are there any performance hits to using a typeConverter in this way?

Advertisements

Microsoft ASP.Net 2.0 Ajax Beta 1 released.

Posted in Ajax Links, Asp.Net, Atlas, CC's Friends, Mochikit, Prototype, Rico, Script.Aculo.Us on October 22, 2006 by Shaun

If, like me you have been following the development of Microsoft’s own flavour of Ajax, codenamed Atlas, for the past six months or so then you won’t be surprised to know that they have released Beta 1 of what will become the released version of the product.

If you never heard of Atlas then fear not.  Atlas, or MS Ajax as I will now call it, is simply Microsoft’s take on the whole AJAX Scene.  AJAX is not a new technology but thanks to Google and a fair few other key players it has become the new must have technology on the web.

AJAX is actually an acronym that stands for Asynchronous JavaScript And XML.  It’s a bit of a mouthful I’ll grant you but its simply a tying together of the different technologies in web development in such a manner that web pages no longer act as a collection of static pages served up on demand.  With AJAX web developers can build web pages that are far more interractive with fewer post packs (page refreshes) because many of the operations on the page happen asynchronously so there’s no need to wait for one operation to complete before another starts.

So What is so special about Microsoft’s offering?  To be honest, not a lot.  the main difference between Microsoft’s version of AJAX and the myriad other AJAX libraries out there is that it is designed to tie in very closely with ASP .net 2.0 allowing developers using ASP .Net to incorporate AJAX into their applications.

Microsoft are not the only ones out there doing this though.
Ajax Pro and Script.Aculo.Us.netare but two I can mention, I’m certain that a quick ten minutes in Google will produce information on others.

Is it worth looking at the Microsoft offering?  I think so.  It’s not perfect by any stretch of the imagination, but the fact that Microsoft themselves are encouraging a community input on the project, and in some cases even making changes as demanded by the community, is encouraging.  The whole project has another upside to as we all get a deeper insight into the Microsoft Developer mindset.  This is encouraging as we get to see that microsoft Developers are not gods after all, they are just damn good at what they do, as are we all.

You can get hold of MS Ajax, and join in with the community here.

If, like me you also enjoy developing non ASP.Net Web Sites and fancy experimenting with adding Atlas to your projects, you may be interested in checking out Mochikit, Script.Aculo.Us, Rico, and the fantastic Prototype framework that most if not all of the Ajax libraries out there are based on.

I have not gone into great detail on any of these libraries here deliberately.  I have often fallen into the trap of simply reading up on one website all about a particular subject and not actually getting my hands dirty.  the result of this is that you know a lot and know nothing all at the same time.  Knowing that you can do x with y is not the same as knowing how to do x with y.  so go and play and then blog your results so we all benefit a little.

Coffee of the Day is Café Elvis, a dark roast from a small farm in Honduras, caffein rush level: 7/10