Coded – Web Development and Programming Blog

C#, ASP.NET, Google, Remoting, AJAX, Silverlight, Web Development

Automatically adding ValidatorCalloutExtenders to your validators

Posted in .NET Framework, ASP.NET, C#, Web Programming by Andrei Alecu on the July 16th, 2008

I recently had to work on a pretty big ASP.NET page with lots of fields that needed to be validated.

requiredfieldvalidator.png We thought it would be cool if we used the AJAX Toolkit ValidatorCalloutExtender control on the validators to keep the validation inline and concise.

To quote from the AJAX Toolkit page:

ValidatorCallout is an ASP.NET AJAX extender that enhances the functionality of existing ASP.NET validators. To use this control, add an input field and a validator control as you normally would. Then add the ValidatorCallout and set its TargetControlID property to reference the validator control.

Because we had over 30 text fields, it would have been really tiresome to add extenders manually to each of the validators. So a way to attach them dynamically was needed.

Fortunately, this is pretty easy to do by iterating through the Page.Validators collection, dynamically creating ValidatorCalloutExtender controls and adding them to the Page.

Challenges

  • The first problem I had was an error that occured when trying to dynamically add controls to the Page.Controls collection:
(more…) Bookmark on del.icio.us

Owner-drawing a Windows.Forms TextBox

Posted in .NET Framework, C#, SharpSpell, User Interface by Andrei Alecu on the September 17th, 2007

This article describes how SharpSpell is able to modify existing TextBox controls to display wavy red underlines below misspelled words.

Here’s an image to demonstrate what I mean:

SharpSpell - ASP.NET spell checker
(This image is borrowed from SharpSpell, but you get the point) (more…)

Bookmark on del.icio.us

Calling a Windows Service from ASP.NET via Remoting & IpcChannel

Posted in .NET Framework, ASP.NET, C# by Andrei Alecu on the September 1st, 2007

I recently had to design a Windows Service that connects to several game servers via UDP, gathers stats, and then updates a MSSQL database.

These stats were then made available in real-time on a web-site written in C# and ASP.NET.

Before Remoting

For the first version of the application, the web-site and Windows Service were completely independent. The web-site would just query the database and determine, or make a best guess about what was going on inside the Windows Service at that exact time. This worked pretty good, and although the database is now about 1GB in size and growing fast, I optimized it good enough for this to work in real-time without a hitch.

There was some caching going on, thanks to the OutputCache directive in ASP.NET, but surprisingly enough there were no performance issues.

After Remoting

All right, so because I needed to display some extra information about ‘online’ users, that the Windows Service knew about, but the database didn’t, I decided to have a look at .NET Remoting. This was my first time working with it.

These were the issues I experienced (as a Remoting newbie) when rewriting the Windows Service to be accessible via .NET Remoting: (more…)

Bookmark on del.icio.us

Google Web Toolkit and ASP.NET?

Posted in ASP.NET, C#, User Interface by Andrei Alecu on the August 29th, 2007

Now that Google’s Web Toolkit is out of beta, I’m looking at ways of integrating it somehow with C# and ASP.NET.

First of all, if you don’t know what Google Web Toolkit is, here’s a quickie: it is a framework for creating Web 2.0 AJAX Web Applications using the Java language, preferably inside an Integrated Development Environment (IDE) such as Eclipse. You then compile this from Java to HTML/JavaScript using the provided tools, and you have a desktop application-like web-page without knowing anything about the W3C DOM, HTML or JavaScript.

What does this have to do with C#?

Well, don’t get me wrong, the ASP.NET AJAX Toolkit is amazing, but being able to visually design a page and use JavaScript behaviors and AJAX from inside an IDE is a step forward.

It seems that Nikhil Kothari from Microsoft is working on a C# to JavaScript compiler, called Script#, as a side project of his. Unfortunately, Script# is not currently supported by Microsoft, and they are really losing ground on the AJAX field because of this. They should promote this to a corporate project, I would love having that same power that GWT has, but directly in the Visual Studio IDE. (more…)

Bookmark on del.icio.us

Generating a transparent GIF image using C#

Posted in ASP.NET, C#, Web Programming by Andrei Alecu on the August 28th, 2007

Problem:

There is apparently no easy way to generate a transparent GIF image using the .NET framework. Microsoft provided a method in the Bitmap class called MakeTransparent() but it doesn’t work for GIFs, it only seems to work for PNGs.

To create a transparent GIF you need to recreate the color table of the image using Imaging APIs, as detailed in this KB article . Unfortunately, this can be pretty slow for an ASP.NET Web application, and it has a lot of overhead, so I needed an alternative. (more…)

Bookmark on del.icio.us