Ok, so you have the greatest control library ever made and Microsoft releases Asp.Net Ajax and none of them work anymore. What is one to do?

Eilon Lipton to the rescue! He writes a very good article about Ajax enabling your controls without linking to the System.Web.Extensions dll.

However, the article is a bit outdated. Here is a piece of code that solves the problems (at least for the latest version of Asp.Net Ajax):
Type scriptManagerType = Type.GetType("System.Web.UI.ScriptManager, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", false);
 if (scriptManagerType != null)
 {
 RegisterClientScriptResourceMethod = scriptManagerType.GetMethod("RegisterClientScriptResource", new Type[] { typeof(Control), typeof(Type),typeof(string) });
 RegisterStartupScriptMethod = scriptManagerType.GetMethod("RegisterStartupScript", new Type[] { typeof(Control), typeof(Type), typeof(string), typeof(string), typeof(bool) });
 }


This is because the namespace has changed since the writing of Elion's article from Microsoft.Web.UI to System.Web.UI and there are two methods named RegisterClientScriptResource and two named RegisterStartupScript so you have to get the right one. Else you get the "Ambiguous match found" error.

There you have it!

The .NET validation framework has two parts, the client Javascript validation and the server validation. That means that the Javascript code needs a value to validate and the server validation needs a property to validate.

So, first step, you create your web user control by putting some controls in it. Then, you want to add a validator to the page to reference the newly created user control. And you get the error "Control '{0}' referenced by the ControlToValidate property of '{1}' cannot be validated.". Why? because every control to be validated needs to be decorated with the ValidationProperty attribute:
[ValidationProperty("Text")]
public partial class ucDate : System.Web.UI.UserControl

Adding the first line to the control tells the validation framework to use the Text property of the UserControl.

Next step, you run the page and you notice the javascript doesn't work. The client validation works on html controls, by looking (recursively) for a 'value' attribute. When one looks at the source code, though, there is no html control that has the id of the user control. It doesn't use a span or a div to encapsulate its controls. All the controls have the id to show they are children to the user control, but the actual user control does not appear in the html source. So what is there to do?

<div id='<%=ClientID %>'></div>

You put all the controls in the ascx file of the User Control into this div. There you go! The validation works!

There is one more quirk regarding web user controls that have more children that render an html object with a 'value' attribute. In that case, remember that the validation starts from the very top, in our case the div. One could build simple javascript functions on the onchange or onsubmit javascript events, for example, to add a value attribute to the div. Best way would be using the onsubmit event, but be careful that the validation sequence also runs on the onsubmit event.

TextBox2.Attributes["onchange"]="document.getElementById('"+ClientID+"').value=this.value";


On popular demand, here is a complete example codeThis is a control that holds two TextBox controls. The control will be validated both on server and client by the value of the second Textbox, the first will be ignored.


using System;
using System.Web.UI;

[ValidationProperty("SecondTextboxValue")]
public partial class vuc : UserControl
{
public string SecondTextboxValue
{
get { return tbValidated.Text; }
}

protected void Page_Load(object sender, EventArgs e)
{
string script =
string.Format(
@"var vuc=document.getElementById('{0}');
var tb=document.getElementById('{1}');
if (vuc&&tb) {{
tb.vuc=vuc;
tb.onchange=function() {{ this.vuc.value=this.value; }}
}}"
,
ClientID, tbValidated.ClientID);

ScriptManager.RegisterStartupScript(Page, Page.GetType(), UniqueID + "_submit", script, true);
}
}


The ascx looks like this:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="vuc.ascx.cs" Inherits="vuc" %>
<div id="<%=ClientID %>"> value="<%=tbValidated.Text%>"
<asp:TextBox ID="tbIgnored" runat="server"></asp:TextBox>
<asp:TextBox ID="tbValidated" runat="server"></asp:TextBox>
</div>


How it works:
  • The javascript validator will look for an html element with the same id as the user control. If it has a value attribute, it will be validated, else it will go to the next control in the hierarchy. If the containing div would not have a value attribute, then the validation would have occured on the first textbox value, as the first element that has a value attribute. That's why the value attribute will be set on textbox change and when first loading the page.
  • The server validation will work because of the user control property that exposes the Text value of the second textbox and the ValidationProperty attribute that decorates the code.


and has 0 comments
I am just linking this small page about the evolution of Earth. You may see when the planet formed, how the moon appeared, the different geological eras, major meteor impacts and extinctions, the evolution of species and some information about the impact humans have on the environment lately.

I've told a lot of people about this, but forgot to blog about it. Shame on me, because this revolutionary concept can change the way we think of sound.

Audio Spotlight enters the category of directional sound systems, more precisely it creates sound from ultrasound. The result is that you can direct a single speaker towards a certain area, and only people in the area can hear the sound.

There are drawbacks, as obstacles getting in the way of the sound beam block the sound from reaching further on. There are limitations to the frequency response and the dispersion pattern. I also don't know if the system can create loud sounds as this would probably need high power ultrasound and I don't know how healthy that would be.

But, even so, the idea is marvelous. As you can see from the animation from the Audio Spotlight site, you can attach a sound to a picture in a gallery, and the sound will only be heard by the people in from of the picture. Imagine that in a museum. Or think about having a restaurant with audio spotlight above the tables, playing whatever music they want and not bothering the other people. Combine it with some form of sound barrier between tables and you get a classy private place with no walls and a lot of people. Or think of a disco where you can separate the sound of each instrument and play it in a slightly offset area so people can dance to the music equalized however they like it. Or even a club where people can hear the music loud on the dance floor and really weak at tables, so they can talk.

This invention comes (of course) from MIT, more precisely from Dr. Joseph Pompei while he was a student at the MIT Media Lab, himself son of another distinguished doctor, Dr. Francesco Pompei.

Update:
However, with great power comes... ah, forget Spiderman! Anyway, there are voices expressing concern on the evil use of such technology. Like this link here, expressing the opinions of Barry Blesser, one of the most respected names in digital audio.

Now, I guess that the best invention ever would be directional earplugs! :)

I found this article on BBC News that told of a series of new algorithms for 3D image rendering using the tracing of light rays rather than polygonal rendering. They also use less resources than traditional algorithms. Interesting enough, so I searched the Internet. I think this will usher a new era of computer games, not to mention a boom of cheap 3D movies. See how the reflections generate secondary and tertiary reflections in the image?

Check out the site of the OpenRT project for videos on how this works.

Update 2011: Apparently the site is pretty much dead except the front page. It's an old post anyway.

Other Links:
Ray Tracing basics at Wikipedia
A free open source (GPL) OpenRT implementation

and has 1 comment
For a while now, whenever I start my computer at work, I get to wait about 5 minutes with my CPU up to 100% due to svchost.exe. Of course, this being an important component of Windows, I cannot delete or disable it, neither can I see what subprocess is causing this utilisation with the normal Task Manager. However, one can download Process Explorer and see a lot more information. I highly recommend it.

Anyway, back to the original problem. I noticed that the problem was the ntdll.dll (ntdll.dll!RtlAllocateHeap+0x18c to be exact) which is, again, a Windows important file.

Only googling to the extreme did I find that the issue is caused by Windows Update, scanning your computer each time you start it. If you disable Windows Update, you don't get the updates, but you get rid of the wait.

Here is a discussion with Microsoft MVPs about possible solutions.
Also, try this link.

And if you do have Process Explorer, you can set the priority of the offending task to Bellow Normal, which will allow you to run any program normally while the Windows Update process runs only on spare CPU. Normal Task Manager does not allow you to change the priority of the process.

and has 0 comments
Windows has a file called hosts, found in Windows\System32\drivers\etc\hosts, that can contain local domain name to ip conversions. It's like a local DNS service with a text database. That means that if you open the file and write 127.0.0.1 www.microsoft.com then every time you try to access microsoft, the browser will redirect to your local machine, effectively making it unreachable.

You can use this to block some of the sites you don't want your child to access or whatever, but most of all, you can disable the access to sites that are known sources of unwanted ads, spyware, malware, etc. Or, as I did, disable access to sites with online games that you are addicted to :)

You can find an updated hosts file at mvps.org. Backup your previous hosts file, for safety, then overwrite it with this.

Update: If you have a blog on Google's Blogger, you should comment (by adding a # in front of the line) or delete the line of the hosts file relating to service.urchin.com #[Urchin Tracking Module], else you will get some javascript errors when entering Blogger. Or you can just ignore all javascript errors.

and has 0 comments
Unfortunately, the lead singer is now in prison after accidentally killing Marie Trintignant, his girlfriend and the daughter of famous actor Jean-Louis Trintignant. This clip is manga-style, but that's not why I put it here, it's because I really like the song.




Links:
Noir Desir at Wikipedia
the Noir Desir site

I've seen many a forum and blog entries that look like the title of this entry. I was frantically trying to find the solution for this a few hours ago and found a lot of questions of the same type, most of them abruptly ending into nothing. No solution, only the questions. What was I to do? Debug!

The problem was that buttons with __doPostBack seemed to work and those with WebForm_DoPostBackWithOptions did not. I pressed them and nothing happened.

Debugging the hell out of the two javascript functions (both used by NET 2.0, on who knows what conditions) I realized that the problem was not in the javascript functions! The problem was a false one.

The real problem is in the validators. If you have a validator on a field and the field has some wrong values in it and both field and validators are hidden, the submit will not work and you will not see what the problem is. Let me make this simple: if you have problems with submit buttons that seem not to work, check your validators!

Now, why the field was hidden and its values filled and the validator enabled is a problem, but that I can fix easily. The "Oh, I am so stupid" phenomenon probably stopped a lot of people posting the solution after they found it.

and has 0 comments
Clive Barker is a man of extraordinary imagination and, while HellRaiser is what people most know him for, I think his "young adult" books are what define him. And by this I don't mean sweaty teenager sex, but wonderful fantasy worlds that also have a tang of darkness and stories that have a conclusion beyond the idiotic morality taught to little children. They are also a bit more actual, without dwelling on feudal or anachronistic features like, say, Harry Potter or Lord of the Rings. I liked "The Thief of Always" and I also enjoy, although not to the same extent, "Abarat".

Abarat is a magical series, much like a darker Alice in Wonderland, with two books currently having been released. The classic "girl enters magical world" is expanded to the point of bursting with the description of the 25 isles of Abarat, one for each hour (including the 25th), each with their own features and crazy-weird inhabitants. Abarat is also a twisted mirror of Earth, with coca-farma conglomerates trying to destroy the magic in the world.

You can find a site at www.thebooksofabarat.com, very nicely done, that teases the imagination with flash animations and excerpts from the books.
I've read a review that compared Abarat to Harry Potter and even declared that it is the writer's alternative to it. I dare say that is completely wrong. The worlds of Clive Barker are about finding your way through your own inner power and imagination, whether you choose the path of Light or of Darkness. Purpose is what defines a Barker hero, not taking sides.

Bottom line, a nice book, clearly well written (I like Barker's style), and the storyline is detailed and well thought of. I may not be in a wonderland mood right now, but it is the best book I've read in the last month. There was an attempt to create a movie based on Abarat schedulled for 2005, but, according to the Wikipedia entry for Abarat, creative differences killed the project.

and has 0 comments
A while ago I presented what I thought it was a very nice flash game from the category of Prince of Persia, Aladdin, Sonic, etc, but simplistic in design and rich in functionality. A demo for world 2 has been published and you can now play it.

and has 0 comments
I enjoyed this book. It is the fantasy story of a medieval land where magic is seen as the most sinful of things, all through the eyes of a woman that falls in love with a magician.

At first, I thought the ideas were nice, as the entire plot reminded me of Berserk , the latest chapters of the manga, and so I upped my expectations a bit too far. Then I realised that, even if the book was written in an even and professional way, I wasn't getting caught into the story. Was it because I couldn't relate to a woman? No, that wasn't it. After a few more uncomfortable pages I realised that the thing missing from the book were true emotional descriptions. The lead character was almost cold, rational as very few women (or any people of that age) would be. The scenes were detailed enough in describing whereabouts or scenery, even facial expressions or human interactions, but no feelings.

I thought to myself "Damn! This is a book as I would write if I started writing one". Funny enough, after I finished the book, the author was described as an American mother of three, who writes books while being a software engineer. I am curious of the percentage of software people that have a lack of emotional vocabulary like I do.

The ending of the book was also slightly disappointing, as I couldn't relate to any of the characters and their actions. The reasons for the story to end like that also eluded me. However, as I wrote in my first sentence, I enjoyed the book, as it was well written. I don't think I will read more of the series.

and has 0 comments
Rarely have I had the honor to read such a boring book. It took me forever to finish it, as you can see, only so I can blog about how unreadable it is. It's not like Iain Banks doesn't have the good ideas that make a book great, but he has no idea on how to use them.

The entire book had the feel it was patched together from pieces of text written with completely different moods by different people. The ideas shifted from one to the other without any sense. The science was ludicrous. And worst of all, the ending had that wonderful "huh?" feeling, when all the plot finally ends just as boringly as it has begun.

And all this in a book that talks about the Universe in the far future, with great empires spanning galaxies and fighting epic battles with weird technologies. I appreciate the effort, but not the result. The book seems like something a writer would do and throw away and a publicist would pick up from the garbage and publish.

and has 0 comments
Update: the band released their first album in December 2009

Last month I blogged about the Romanian band called duteVino. On the 8Th of March they had a concert in Suburbia and I decided I should go.

The bar is nice. It is slightly smaller than Fire, but a little classier, with small tables and taburets on one side and with a more open space (less colonnades). I got there with my wife and a friend and hunted the chairs until we had some table space.

The band started singing soon enough and they sounded really nice. The girl vocal has it all: the looks, the voice, the nicety. The band itself is made of four people and, since I am not a musician, I can't comment on the quality of their instrumentation. They sounded OK to me. duteVino played (I think) all the songs from their upcoming album, ten in total, and Gruv they left for the encore piece.



Unfortunately, the sound engineer was a moron. It's not like you can find good sound engineers anywhere on the street, but at least find one with guts! You see, the "chicken" way is to maximize the sound of instruments and minimize the sound of the vocal. In this way, even if there is faltering in the voice, most people won't realize it. Or at least I think that's the explanation why most concerts leave you almost deaf from the sound of the instruments while you struggle to understand (or even hear, as was the case here) what the vocal says.

The result here was that the voice of the singer was almost inaudible and I wonder if I would have enjoyed the concert if I didn't know some of the songs beforehand.
All in all, I like the band. I won't call myself a fan, but I will try to buy their album, nonetheless.

Ok, let me feed my weird side. This is the soundtrack of a very nice anime series, itself spun from an anime movie called Ghost in the Shell. The series was called GITS - Stand Alone Complex and this was the opening song. This is not the official video for this song, especially since it depicts images from the movie, not the series, but I liked it better. Enjoy!

The original video was removed from YouTube, this is another, same song.

[youtube:h71xGNXpRVo]


Inner Universe - GITS SAC OST
Composed by Yoko Kanno
Performed by Origa
Click here for lyrics and details.
You can also download the manga for Ghost in the Shell and its sequel (GITS 2 :) ) at narutocommunity.net, after a very annoying registration and a lot of popups (or javascript errors).
Try these direct download links, although they might not work:
Ghost in the Shell
Ghost in the Shell 2
Warning: don't use multiple connections or download accelerators. This site only allows one connection from one IP, apparently.

And here is Making of a Cyborg, by Kenji Kawai, the original soundtrack for the movie.

[youtube:-u77XdL8_B4]