Tuesday, May 25, 2010

ASP.Net TreeView SelectedNodeChanged doesn't fire!

Well, there are a lot of good reasons why that could happen because of your bad code, but this time it is a plain ugly Microsoft bug. You see, the code in the RaisePostBackEvent method in the TreeView control first checks if the control has an Adapter and if not, it just does its thing. If there is an Adapter, it tries to cast it to a IPostBackEventHandler and then fires the RaisePostBackEvent event there. However, if the TreeView control has an adapter and it is not a RaisePostBackEvent, nothing happends!

Here is the offending code:

protected virtual void RaisePostBackEvent(string eventArgument)
{
base.ValidateEvent(this.UniqueID, eventArgument);
if (base.IsEnabled)
{
if (base._adapter != null)
{
IPostBackEventHandler handler =
base._adapter as IPostBackEventHandler;
if (handler != null)
{
handler.RaisePostBackEvent(eventArgument);
}
}
else ...


Bottom line, you need to either not use an adapter for the TreeView, or use one that knows how to handle the postback. And given the complexity of the code in the method, it is better to just not use an adapter.

The solution I have adopted is to recreate the functionality in an override of the RaisePostBackEvent method and add some more (like TreeNodeClicked and SelectedNodeClicked). Hint: you need to also get in LoadPostData and remember which nodes are selected in order to check if the selected node has changed.

Gecko (Firefox and Chrome) Javascript redirect and history issues

Wow, long title. The problem, however, is simple: when adding an inline Javascript script block that changes the window.location or window.location.href properties, FireFox and Chrome do not retain the original URL of the page in the browser history. The Back button doesn't work correctly.

Going to the Mozilla page for developers I find that both redirect methods are equivalent to location.assign(url) which implicitly sets the url in the browser history chain, as opposed to location.replace(url) which doesn't affect the history and just replaces the current URL. So I get to use one method and get the behaviour of the other!

Enough said. Long story short, the behaviour was not reproduced if the same script was being loaded in a button click event. That means it is another of those annoying Gecko page load completed issues.

The solution? Instead of location=url; use setTimeout(function() { location=url; },1);. I know, really ugly and stupid. If you find a better solution to cause a redirect from javascript, please let me know.

Wednesday, May 19, 2010

WPF Converters as markup extensions

I am only linking to this blog post that shows how to instantiate the converters directly in the binding, without having to define a resource just for that.

WPF Quick Tip: Converters as MarkupExtensions

Update: After careful deliberation I've reached the conclusion that instead of custom converters that would have to be instantiated in the binding XAML I can just create new binding types. Here is how you can do it:
  1. Inherit from Binding
  2. Implement IValueConverter
  3. Set Converter=this in the constructor
  4. Use the new binding where you see fit


Actually, I have created a more complex Binding object that chooses the type of conversion based on an enumeration or, alternatively, gets converters as content and pipes them one after the other for a more dynamic reuse of converter power. I am still not sure which of these two solution I will use more often, though.

Monday, May 17, 2010

AC/DC concert in Bucharest

The concert was supposed to start at 21:00 and end at 23:00, so at about 20:57 my friends started saying that the show will probably start at 22:00, because "all the bands" do this. Three minutes later, AC/DC started singing. I could have synchronised my watch by them. Also, at 23:00 they left the stage. The entire show was professional to the second, things worked almost perfectly, the coreography of their stage actions being totally in sync with the cameras, lights and other props.

I am not a great fan of the Aussie band, I like their music, but I only used to listen to their music when I was a child and I was falling asleep on Highway to Hell. Maybe that's why I thought that song and For Those About to Rock were the best of the songs and the rest weren't even close. But they were good enough.

I thought the vocal didn't quite have it in him, since after about an hour, the guitarist started a solo that lasted for 15 or 20 minutes. The energy in that man (Angus) puts me to shame and would have put me to shame even when I was a teen! While the audience was stuglling with the uncharacteristic cold weather and freezing wind, Angus Young was running around in his underwear, playing the guitar as he did so.

Here is a video from the event. Hav fun!

Dust of Dreams by Steven Erikson

book coverI don't know what to say about Dust of Dreams. It is the first book in the Malazan Book of the Fallen series that is only partially finished, only the first part of a larger story, spread over the ninth and tenth books of the saga. Since the last book from the series, The Crippled God, is not yet released, I have to wait for a year until I get to know what happened.

This being said, I don't really know what happened in this book, either! The Adjunct moves all her forces towards Kolanse, the last of the K'Chain Che'Malle are rising up, there is a group of undead Jaghut that work together, two pairs of Eleint blooded ascendants that have yet to betray each other, a bunch of semi-undead (they have their memories) T'Lan Imass, three pesky gods, a schizophrenic Icarium... the list goes on and on... One thing is for certain: I doubt the tenth book will be able to satisfyingly end the story. The huge number of storylines pretty much guarantees it.

So, I liked the book, but I feel I need to reread it to understand it, maybe just before the tenth one is released. Meanwhile, I am oscillating between the Vorkosigan Saga and the Discworld Saga... Whatever should I start reading? Considering they both have about 20 books each...

Update: It seems the release of The Crippled God has been delayed until 2011, even if there were hopes it would appear in libraries this autumn. Damn!

Hidden Gems in ASP.NET 4.0

Here is a post from Phil Haack about extra extensibility options in ASP.NET 4.0. I would like to emphasize the third "gem", the one that lets you add an assembly programatically to the list of loaded assemblies (equivalent to adding it in the assemblies tag in web.config). I wanted this from .Net 1.0 ! Unfortunately it must be called during the Application_PreStartInit stage of the application, but maybe the first gem can help with that.

Of course, I haven't been using these things yet, so I may be saying stupid things. It is a distinct possibility... Quite distinctive... Oh, shut up!

Friday, May 14, 2010

If this works, it could have an impact similar to the contraceptive pill for women

My personal opinion is that the freedom women now enjoy comes a lot from the humble contraception pill. Indeed, who would have the resources to pursue a career, fight for their rights or have a life of their own if only the men would carry the responsability for sexual protection? The pill allowed women to break the recursive loop, so to say.

Now, men have used condoms for a long time, with various degrees of efficiency, though. Sometimes they break, sometimes mysterious holes appear in them, sometimes they are so annoying they are not used. The search for a contraceptive pill for men is ongoing, but even if some progress was made, it is not yet a usable solution.

Here come James Tsuruta and Paul Dayton with "A Sound Decision", a method which would involve placing your balls into a liquid, zapping them with ultrasound and become sterile for a specified period of time.

Can you imagine the social impact this could have?

Wednesday, May 12, 2010

Error installing the .NET Framework 2.0 SP2 Security update KB974417

First of all, check the WindowsUpdate.log file found in the Windows folder. It should tell you how the update failed. Look for something looking like this: WARNING: Command line install completed. Return code = 0x0000066a, Result = Failed and later on WARNING: Install failed, error = 0x80070643 / 0x0000066A.

If you have the same error, check this article out: Fix KB974417 Installation Failure—Microsoft .NET Framework 2.0 Service Pack 2 Security Update for Windows 2000, Windows Server 2003, and Windows XP.

However, my problem was that I had NOT installed the KB976569 Windows update that the guy recommends removing before installing the new one.

I found this article: KB 953297 and KB974417 Fails to Update Through Windows Update that recommends a clean reinstall of the .NET Framework. Haven't tried it, though. I just didn't do the update. Probably when all hell breaks loose I am going to regret it, but at least I passed the message on :)

Science of social networks

I am a great TED Talks fan, where most of the talks are impressively smart and useful and well presented, but this one I just had to embed. The title is a little misleading, if you ask me: The hidden influence of social networks. It is more about how statistical analysis on social connections yields all sort of interesting information about the human condition. Enough of this, watch the talk:

Tuesday, May 04, 2010

Multiple controls, same ID, different containers!

I was minding my own business doing this ridiculous ASP.Net project and suddenly I am hit with: "Multiple controls with the same ID 'lbTitle' were found. FindControl requires that controls have unique IDs.". I was using this web control that contained two others, each of them having a lbTitle control.

If you think about it, it does make sense to throw this exception when the FindControl method is used in the parent control. Which control did I mean? But the error appears even if the FindControl is used inside one of the child controls, what is up with that?

As a secondary thought, I wasn't using any FindControl. It seems that what does is the AssociatedControlID property of the Label control. Therefore I will set the HtmlTextWriterAttribute.For attribute manually to resolve this. Pretty damn ugly, if you ask me!


Update: My fault! The controls needed to implement the INamingContainer interface. It's not that the ClientID was not different, but FindControl works by going to the NamingContainer control and finding then children by ID. Too bad that you can't just specify the ClientID and be done with it, but that's that.

Monday, May 03, 2010

ASP.NET 4.0 allows CON, PRN, COM, LPT and NUL in the URLs

I don't want you to think that I started working on ASP.Net MVC, but this article about a 36 year trek through backward compatibility hell was really funny and needed to be linked. What is so funny, I guess, is that it is factual and the humour is in the situation more than in the article itself.

On a separate note, ASP.Net 4.0 fixed this issue with a web.config setting.