Well, I have been trying to build this control and from day one I had weird issues with the display on Internet Explorer 7. Apparently, because of a bug Rick Strahl reported in his blog, elements that have the position relative escape their containers when the containers themselves are not relative. You will see there a comment from me when I hadn't really understood the problem :(

With the jQuery UI resizable plugin, the base functionality is to change the entire body of the resized control to position relative, causing all kind of trouble, only to permit the resize handles to move around the element (like the south handle having a bottom setting of aproximately 0 px). So, after making all kinds of changes to the javascript in order to solve the IE7 relative position bug, I finally submited and started changing the resizable plugin itself.

The idea was simple: remove position relative, make two divs, one inner and one outer, resize them both in the same time, while another div placed in between would act as the south handle. But it didn't work. I couldn't set an element external to the resized element as the handle, as explained here.

The fix above, though, doesn't entirely show the dimension of the problem. The resizable plugin is incredibly buggy! The documentation says that you can specify custom handles either as jQuery strings or as elements or jQuery objects. That is not correct, as the handles passed as objects are stored in a handles field, but then another _handles field is initialized and the first completely ignored! Also, as in the post above, you need to bind the javascript events to every external element as well, since the original mouse capturing events are placed only on the resized element.

Ok, so the fix is this:
  • look for a this._handles = $('.ui-resizable-handle', this.element).disableSelection(); line. This is where handles is being ignored. Replace it with:
    if (this.handles) {
    var handles=$('nothingReally');
    for (var i in this.handles)
    handles[handles.length++]=this.handles[i][0];
    this._handles=handles;
    } else {
    this._handles = $('.ui-resizable-handle', this.element)
    }
    $.each(this._handles,function() { $(this).disableSelection(); });
  • look for a _mouseInit: function you will see there a line like this.element.bind... you need to add a similar one underneath for all the handles:
    // Add mouse events for the handles as well
    if (this._handles)
    for (var i=0; i<this._handles.length; i++) {
    $(this._handles[i]).bind('mousedown.'+this.widgetName, function(event) {
    return self._mouseDown(event);
    })
    .bind('click.'+this.widgetName, function(event) {
    if(self._preventClickEvent) {
    self._preventClickEvent = false;
    event.stopImmediatePropagation();
    return false;
    }
    });
    }


The change here allows to pass objects (either elements or jQueries) as handles, thus allowing for external elements to act as handles. Removing 'this.element' from the query is not a good idea in case you want to use more resizable controls on the same page. You want only children of a container to act as handles. It could work to move upwards on the control tree until you can get a child that fits the string jquery, but I think that's overkill.

Hope that helps someone.

I made a few controls that loaded and included a resource js file. And it all worked well, until I wanted to load the js file from the Page object. The generated url was invalid. After hours of nervewrecking attempts I realised that the problem was I was using control.GetType() to get the type required as a parameter in GetWebResourceUrl. And the page, even if inheriting from a custom page object that resided in the assembly where the embedded resources were, was of the site assembly.

Solution: use GetWebResourceUrl(typeof(knownClassInTheAssembly),resourceName);

Warning: my object was inherited from Page and placed in the necessary assembly. And it still didn't work. It is good to remember that ASP.Net pages are not of the type they inherit from, but a class with the name of the page and that resides in the dynamically generated assembly of the site! So be careful where you use this.GetType()

Update 3rd of March 2016: I've tested for this bug with the latest versions of Internet Explorer, Firefox and Chrome, using the latest jQuery libraries (1.12.1, 2.2.1 and 3.0.0.beta) and it could not be reproduced. The rest of the article may be obsolete.

So I am building this new jQuery based control and I am terribly smug about it until I run the test site on FireFox. Kaboom! Nothing is working. Why? Because FireFox has some issues with the computed style on hidden elements and jQuery people just don't want to fix the problem. But hey, jQuery is open source, right?

So, let's detail the problem. Here is a jQuery bug posting that explains far better than I could what is going on. Apparently, the offsetParent of a hidden element is null in FireFox and the jQuery core function returns the document object when null is given as a parameter [ $(null)==document ]. Then running the FireFox specific function for getting the computed style [ document.defaultView.getComputedStyle(element,null) ] throws an error because the element is now document and it has no style, only its body has.

So, why not fix that? The FireFox error text is '[Exception... "Could not convert JavaScript argument arg 0 [nsIDOMViewCSS.getComputedStyle]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: /jqueryJsFile/ :: anonymous :: line 1349" data: no]'.

The line number might vary with the type of jQuery file version you are using and the amount of modifications you have done to it. What you should find at said line is something like: var computedStyle = defaultView.getComputedStyle(elem, null);.

Solution: Just add above it if (elem == document) elem = document.body; and it solves this particular issue.

In the minifyied version look for var M=q.getComputedStyle(I,null) and add before it if (I==document) I=document.body;


It would be far more elegant to address the problem where the offsetParent is assumed to be not null, but with so many plugins for jQuery, you can't just test them all.

I met an especially obnoxious situation where I had deployed a perfectly working control library on a server and then, when testing how it worked using the remote browser on that server, I noticed only some of the resources where displayed. Mainly, some PNG files where not loaded.

Funny enough, if I went to the properties of the displayed images I saw their correct size. That actually meant that they were loaded correctly, so it wasn't a WebResource.axd issue. The remote browser was Internet Explorer 7, which has no problems displaying the PNG format. After changing all the images to GIF, I also found a solution for that problem.

Some "security" feature in Windows, especially Windows Server 2003 SP1, but also in SP2, messes with some PNG images being displayed. Probably, that security option was implemented to fix this issue. Here is the Microsoft knowledge base article detailing the fix.

So you have some embedded resources in your ASP.Net control library and you want to use them. But instead, nothing works. Scripts are not loaded and images are not displayed.

Look in the IIS log files and check for an error like this: "Exception information: Exception type: ArgumentOutOfRangeException Exception message: Specified argument was out of the range of valid values. Parameter name: utcDate".

If you see it, then your assembly where the resources are embedded has the build date into the future! This also applies to the code you just built and the date is correct and the date of the server where you want to copy it to is in the past. It also applies when the time is in the past, as when you are copying it on a server in a different timezone!

Update: There are other reasons why axd files are not loaded. One of them is that some other IHttpHandler (defined in web.config) is messing up with your settings.

Another is that the .axd extension is not defined in the virtual directory mappings (You get the dreaded Webform_PostBackOptions is undefined javascript error). Go to IIS manager to the properties of the virtual directory, click on the Configuration button, select the Mappings tab. You have to have the axd extension defined to open with aspnet_isapi.dll. Warning: there is a checkbox in the properties for the extension mapping called Check that file exists. Make sure it is unchecked, as the WebResource.axd and ScriptResource.axd are not actual files, so the mapping will fail if the check is set! On Windows 2003 there is also a listbox at the bottom of the Mappings tab. Edit it and look for yet another Check that file exists checkbox and, of course, uncheck it.

Ever wanted to bind something to the layout rendering phase of an element in Javascript? This helps, by checking at a fixed interval if the size or position of an element have changed and, if so, firing the 'refresh' custom event. All one has to do is then bind to it.

Github page: https://github.com/Siderite/jGenerateRefresh
JQuery plugins page: http://plugins.jquery.com/node/9030

Example:
$(function() { 
$('#target').bind('refresh',{},someRefreshFunction);
$('#target').generateRefreshEvent(100); // every 100 milliseconds
});

Wow! This book is a must read. Not only because it is short, well written and freely available online, but because it does what very few books manage to do lately: actually showing you how to practically apply the knowledge and the consequences of that. Basically, it's like a technical book with a story.

As the title suggests, Scrum and XP from the Trenches is a book about software management, moving step by step through all the requirements of the management process in a Scrum environment and showing in detail what Henrik's actual implementation was, the problems he encountered, the options he had and why he chose one, the other, or a combination thereof. Even if he talks mostly about Scrum, he does mix in the elements of XP that he thought worthy of borrowing, making this not a book on any management theory, but of a real life process.

As previously mentioned, the book is freely available on InfoQ, although you are highly encouraged to buy the book to support Henrik Kniberg and other endeavours like his. A must have for any manager or team lead, and a very good read for any developer, having the chance to glimpse at a real software work environment.

For me I am glad to have read it and to see more of my current job in the book than the previous one, which means I have actually moved upwards and not only horizontally.

It seems that there is a renewal of the non-relational database movement. Since I know nothing about the specifics I will list only a few links that I found relevant:
No to SQL? Anti-database movement gains steam
NOSQL debrief
Neo4j - The Benefits of Graph Databases

Of course, this "revolution" is only gaining momentum because of the huge quantity of data being moved around on the web. There can be no centralised system that could handle Google, Facebook, Amazon data sizes and therefore they all move to distributed systems. Tables are now a hinderance, rather than a programming advantage and object oriented schemas step forward.

Will that change our daily work as developers? Well, only if we decide to use some "live" database system to store our data. As proven by the previous "revolution", relational works pretty well for small systems or networks.

As you have probably noticed, a lot of my recent posts have been about WPF. Having to do a demo in this new (for me) technology I had a lot of thing to learn and a lot of brick walls to hit. It was exciting, but also difficult, with new concepts that felt awkward, mind twisting. I even burst one day shouting "I hate WPF".

However, I am now working, temporarily, with ASP.Net (no Silverlight) again. And guess what? At every step where I need to design something, I think in the WPF way and find the web way lacking. Riddle me this, riddle me that. :)

Of course, some might say that this is another proof of my whiny personality. I hate when people say that about me!

I only met this while working on a Menu control, but who knows, maybe it occurs in other situations as well. Bottom line I wanted to create a CSS friendly Menu without using an adapter. So I inherited from Menu, did some stuff, then Kaboom! "A PopEndTag was called without A corresponding PushEndTag" error.

I could not determine where it cam from. The only helpful article on the net seemed to be one from a guy that also wanted to inherit from Menu. Strangely enough his problem only appeared in Design mode, while mine was a runtime thing. And weirder still, the problem was "solved" by the same ridiculous fix, that of calling an extra
base.RenderBeginTag(writer);
in my RenderBeginTag method override. However, his explanation that is all came from IControlDesignerAccessor did not solve anything for me. Menu only overrides the SetDesignModeState and GetDesignModeState methods from IControlDesignerAccessor and when I also overrode them and removed any code inside, I still got the error.

So, after an hour of searching, I solved it by overriding the Render method with
protected override void Render(HtmlTextWriter writer)
{
if (this.Page != null)
{
this.Page.VerifyRenderingInServerForm(this);
}
if (this.Items.Count > 0)
{
this.RenderBeginTag(writer);
this.RenderContents(writer);
this.RenderEndTag(writer);
}
}
which is the exact implementation from the original Menu source code, but without the 'false' parameter in RenderContents and RenderEndTag.

Hope it helps someone.

In C# 2.0 and above there is this new feature of the '??' double question-mark operator that operates like the SQL isnull function. If x is null then x??y will return: x if it is not null and y if x is null.

A bit annoying, though, that Javascript does not have an operator of the sort. Or so I thought. Enter ||, the logical OR operator. In fact, in javascript x||y will return y if x is null. Also if x is undefined, string empty, 0 or false. But it works in a reasonably similar manner. Beats x===null?y:x anyway.

This is called Short Circuit Evaluation, if you want to be pedantic about it. Be aware that you can chain it, too, similar to a Coalesce function:
0 || null || '' || false || undefined || 'something' // result 'something'

and has 2 comments
I have this Genius Comfy KB-16e model K640 keyboard. I went to the Genius web site and downloaded the drivers and Media Key application which is supposed to control what the "media" keys are doing. But the application is crap. It only shows some of the buttons I have and some I don't. Most annoying, I don't have listed the buttons for previous/next track.

The solution is to modify the registry. If you go to the Media Key installation directory (typically in Program Files) you will see a registry file called Magickey.reg. It holds all the information loaded in the reg by the installer of the Media Key application. Open it with notepad (not by double clicking!) and search for "Function Table". You will see a bunch of equalities like:
"0000000B"="Show MediaPlayer"
You will need to write somewhere the numbers associated with the keys that don't appear in the Media Key application. In my case
"00002000"="Previous Track"
"00002005"="Next Track"
Ok, now run regedt32.exe from the command line (or Run command in the Start Menu) and navigate to HKEY_LOCAL_MACHINE\Software\WayTech\Versato\System. You will see there stuff like button1, button2... and their values 0000XXXX or some string holding a path. All you have to do is double click on the buttons that hold the numbers you wrote down as the value (in my case 2000 and 2005) and write instead of the value a path to a batch file or an exe file. I use bat files so I can change them later.

So, in my case I double clicked on button17 and button18 and filled the value with C:\Batches\prevTrack.bat and C:\Batches\nextTrack.bat. And now it works. I am sure you can change something in the registry to actually make the buttons visible in the Media Key application, but I don't care about that. If you do it, please let me know.

If you have the same problem as I do and all you want to do is set up your Music, PlayPause and Prev/Next buttons, take the text below and write it into a file with the .reg extension, change the paths to your own batch files, then double click on it:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\WayTech\Versato\System]
"button7"="C:\\Batches\\playpause.bat"
"button8"="C:\\Batches\\playlist.bat"
"button17"="C:\\Batches\\prevTrack.bat"
"button18"="C:\\Batches\\nextTrack.bat"

and has 0 comments
I know, Might and Magic IX is an old game, but I haven't played it because, after being a HUGE fan of Might and Magic 1 through 5 I got really dissapointed with versions 6,7 and 8, which used 3D technology, but presented a lot less as the game story and playability was concerned. Then I played the tenth version, Dark Messiah of Might and Magic, which was a completely different game, more of an Arx Fatalis 2, rather than M&M 10. Not that it wasn't very very cool, just wasn't what I had expected from an M&M game.

Enter Might and Magic IX. From the start it looked less modern than versions 6-8, which prompted my friend to think that he played more recent versions of the game. It became soon apparent that it was an attempt to go back to the roots. The game was complex, the map large, the monsters inventive and the storyline pretty interesting. Also, they returned to the old solution of dungeons, where entering a place was moving you to a new map, rather than a small part of the larger one.

I loved every moment of it until close to the end. The cities at the end of the game had less stuff in them, less monsters around and of a more poor quality. I kind of expected that, since it must have been a long software project plagued by a release deadline in the end. However, when I had to spend hours trying to get around dungeons filled with powerful yet silly monsters just to get to the end, I got very bored. I actually did not finish the game, only about 95% of it.

The game had an unhealthy amount of undead creatures, which made Turn Undead a very useful spell. Unfortunately, I think it was a bit buggy. After a strong Turn Undead monsters continued to run, even if the spell wore off. Another really nice spell was Enrage, which allowed one to make monsters fight each other. Wizard Eye was a bit annoying, since it lasted a too short a time.

I recommend you check the character development tree (Druid, Healer, Lich, Gladiator, Assassin, etc) and decide from the very start which character in your party will be what. Pay extra attention to the promotions. You may be able to promote more characters in the same time, but then you are commited to that path with all of the characters. Try to build each character in a different class. Some allow for very powerful spells that one cannot learn or use otherwise.


I don't want to spoil anything, so I will let you play it and enjoy. I applaud the return to the old values of Might and Magic, even if those older games had a lot more brain and humour in them and this had a lot of braun. The ending was inconsistent with the M&M storyline so far which was disappointing.

Bottom line: greatest of the true Might and Magic 3D games, I wish I was young again and full of free time so I can play it without looking at the clock all the time. If you somehow missed it, do play it.

and has 1 comment

Foundations of Programming is a free ebook written by Karl Seguin, a member of the CodeBettter community. As you might have guessed by now from the fact the book is free, he is Canadian. :)

There is even a Foundation of Programming site, where there are a lot of free resources on programming as well as other free ebooks.

About the book, it is a good read. A bit inconsistent, it seemed, since it starts with chapters on Domain Driven Design, Persistence, Dependency Injection, Unit Testing, then moves to Object Relational Mappers and then has three "Back to Basics" chapters about Memory, Exceptions and Proxies. There is a logic to this, but the jump from expert to junior programming and then back again was a little annoying.

Interestingly enough, Karl Seguin is a former Microsoft MVP that advocates ALT.Net.

Bottom line, it is a good and easy read for all levels of programming. People might be attracted to the way Karl is expressing his opinion without actually being biased towards any of the usual debate parties. Beginners might learn about the foundations of the stuff they take for granted, like heap/stack, while more advanced developers can start thinking about structured ways of doing work, like DDD and automated unit testing. Neither chapter is a complete new revelation, but taken together, they do present a clear picture of programming from Karl Seguin's perspective and can surprise you on matters you thought you had complete control over.

and has 0 comments
Something really cool from the TED blog, this image is an optical illusion of grand scale. See the Cyan/Green spirals? Well, they are the exact same color. Trust me, I opened Paint.NET and checked their RGB values. Event at immense zoom, the colors still appeared as different.