Wednesday, March 10, 2010

Adventures while building a Silverlight Enterprise application part #32

Today we want to look at a pitfall when debugging certain data binding code. But first I have some other stuff I wanted to share with you.

It’s been over a month. Where have you been?!?

I’m sorry I couldn’t post in the past month. I’ve been really busy with a lot of different stuff. As you might already know, I’m having a new house built and it takes a lot of my free time.

My working time has been busy as well. I have a new role as team lead for a small team now, which took a lot of time to prepare for. Also I’ve been training a group of people to build software with our new framework. All in all, it’s been a hectic time and I don’t think much will change in the next couple of months.

So you’ve been completely off the grid?

Well, not completely. I’ve written my second article for SilverlightShow.net, which you can find here. The article describes how I built a simple interactive spider, that uses JQuery from Silverlight to get pages from the web. There is some nice code to parse HTML to get links and there is a simple but effective data binding trick in there, so go check it out.

Also, I’ve done some thinking about where to go with this blog. One of the things I’ve decided is that I will stop development on CodeEmbed4Web as I found there are better ways of embedding code in my blog posts. It will still be up for download and if anyone is interested in the source, drop me a line.

But enough about all that, let’s get down to business.

Warning! Debugging can be hazardous for your health and it can even be deadly!

So here is the case. I was working on a feature in our application, where I needed some code to run whenever a certain property was set by the user. I went and tested my code and everything worked as expacted, until…

…I first entered a new value in a TextBox control and right after that I clicked a HyperlinkButton which should trigger code to save the change I made. Because of a breakpoint in the previously mentioned code, I ended up in Visual Studio. I pressed F5 to continue running the application and then I checked to see if my change was actually saved and to my surprise, it wasn’t!

I placed a breakpoint in the clicked event of the HyperlinkButton and tested again, only to find out that the clicked event never fired. I went on and started debugging the whole code trail that should have let up to the click event, but with no luck.

Eventually I decided to build a small test application, as I find them easier to analyze. I tried replicating the same behavior, but the only way I could get it not to register the clicked event, was by showing a MessageBox whenever the user changed a value right before clicking the HyperlinkButton. So I went back to the original application and tried to find any code that might have a similar impact and I obviously came back empty handed.

Finally, after trying out different controls, changing properties, etc., I decided to remove all the breakpoints from my code and try again. All of a sudden everything worked! As it turns out, debugging code that is triggered before a click event (like data binding code, which is triggered as a result of loosing focus, which is executed first), will prevent the click event from firing. Thinking about it, it all makes sense, but when you’re debugging it, it doesn’t. Debugging is deadly!

No comments:

Post a Comment