What's hot ? (and I mean really ...) - scroll down for more
1).  Code Templating - advanced usage of delegates & generics: my slides & demos are available for download! CodeProject article is also available.

2).  My series "TDD in the eyes of a simpleminded" is in progress(including code!): preface, part1, part2, Q&A 1, Manual Stub .vs. Mock Stub

3).  TDD Workshop: SeeCompass v0.1 and v0.2 are out.
# Sunday, May 14, 2006

Preface:

Let's say that you have Button control named myBtn and you want to handle its Click event:

myBtn.Click += new EventHandler(myBtn_Click);

static void myBtn_Click(object sender, EventArgs e) {
   // do something
}


Now, raise your hand if you ever attached the event handler to the event manually, meaning you wrote "new EventHandler(myBtn_Click);" or even specified the method signature "void myBtn_Click(object sender, EventArgs e)".
I don't know about you, but the way I work is by simply writing "myBtn.Click +=" and this magic yellow thingi appears:

autoCompleteEvent.gif

TAB-ing again will generate the method stub and I'm good to go.

Doing this yellow magic on delegates parameters:

We all(?) worked with List<T>. This nice class has some nice methods like ForEach, FindAll, Find etc which get delegate(Action<T>\Predicate<T>) as parameter. for example: 

List<int> numbers = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });

// Print the numbers via ForEach method
numbers.ForEach(
delegate(int i) {
   
Console.Write(i);
});

Would it be great if you can write something like:

numbers.ForEach(

And the yellow thingi will popup and by clicking TAB this code will be generated:

numbers.ForEach(delegate(int i) {
   //TODO
});

This means that this IDE feature should check the type of the delegate - the number and type (even generic type!) of parameters and the return type. This will prevent us from looking at MSDN or "Go To Definition" while working with delegates which are sent as parameters.

Time for you to make a difference:

what say you ? can this save you some time ? If so - leave a comment, I'll do my best to implement it or to forward this request to MS folks (as ladybug).

Posted by Oren Ellenbogen 
14/05/2006 12:27, Israel time UTC+03:00,     Comments [5]  | 
# Saturday, May 13, 2006

We got up at 07:05. It was hard as hell, but we had to put the effort for the team. After all, we came to hear some great lectures. No way in hell I'm gonna miss it... Oh, and there are many pictures to see, come on, I know you want to see this one !
Posted by Oren Ellenbogen 
13/05/2006 07:37, Israel time UTC+03:00,     Comments [3]  | 
# Friday, May 12, 2006

So it all began on Tuesday, Moty (CEO), Roee(CTO), Ken (Team Leader and a major guffy) and myself drove about 5 hours to Eilat...
Posted by Oren Ellenbogen 
12/05/2006 09:30, Israel time UTC+03:00,     Comments [0]  | 

Man, that was a good 3 days of great lectures, great people and one great great party ! I had so much fun, really, and I'll try to share with my enthusiasm during the following 2-3 posts. Prepare for plenty of reviews about the lectures I've went to and a big set of pictures.

I got a lot of inspiration from some of the lecturers at TechEd and I can't tell you how much I'm excited about my lecture this week, I've invested a tremendous amount of time in it so I hope it will turn out the way I'm want it to be. It will be a dream come true to lecture on one of the next TechEd, so I hope I'll have some chances to share with you my motivation and my passion about our world(programming rules!).

All in time, I guess.

OK - on to the next post !

Posted by Oren Ellenbogen 
12/05/2006 08:56, Israel time UTC+03:00,     Comments [0]  | 
# Monday, May 08, 2006

In the previous version of asp.net, v1.1, the CustomValidator did NOT run when the control(e.g TextBox) was empty. Possible solutions were to create your own control (something like RequiredCustomValidator : CustomValidator) or the change WebUIValidation.js file so it will actually validate the control even if it's empty. Now, in the new version, v2.0, you can simply set the ValidateEmptyText to true and you're done. Nice (and useful) !

Posted by Oren Ellenbogen 
08/05/2006 04:02, Israel time UTC+03:00,     Comments [2]  | 
# Friday, May 05, 2006

I know, this is kind of a childish post but heck, It's hilarious to hear someone tries to pronounce my name - kudos Chuck, you did it !!

Click here to download the podcast (btw - my "thing" starts at -5:38).

Thanks Chuck, I'll update my progress on this one so keep reading ;)

Posted by Oren Ellenbogen 
05/05/2006 07:19, Israel time UTC+03:00,     Comments [3]  | 

The using keyword works on objects that implement IDisposable interface (an interface with one member, the Dispose() method).
So a code like this:

using (SqlConnection conn = new SqlConnection("connection_string"))
{
    // use conn...
}

Is actually transformed into:

SqlConnection conn = null;
try
{
    conn = new SqlConnection("connection_string");
}
finally
{
    if (conn!=null)
        conn.Dispose();
}

The using keyword allows more elegant writing, nothing more actually.

The additional feature I would like to see is that in case of exception, a method in the implementor of IDisposable will be called, meaning the code should(?) be transformed into something like this:

SqlConnection conn = null;
try
{
    conn = new SqlConnection("connection_string");
}
catch(Exception err) // *
{
    HandleException(err);
}
finally
{
    if (conn!=null)
        conn.Dispose();
}


Of course, I would have to implement HandleException(Exception e) method as part of implementing IDisposable interface.

Why is this good for ??

Well, think about creating a transaction scope interface:

interface ITransactionScope : IDisposable
{
    void Commit();
    void Rollback();
    // ....
}

In this scenario, it would be great that if no exceptions were thrown, the transaction should Commit() by default,
but if any exception was thrown and not handled - do Rollback().

using (ITransactionScope trans = DbServices.StartTransactionScope())
{

    // delete 1

} // should do Commit()


using (ITransactionScope trans = DbServices.StartTransactionScope())
{
    
    // delete 1
    
    throw new ArgumentException("just to make the point clear");

} // should do Rollback()


HandleException(Exception e) will allow me to set a flag for Rollback on Dispose or to Rollback immediately; This can be quite handy.

Today I Rollback at the Dispose(if the transaction state is "uncommitted") and I force my programmers to call Commit() method directly.

* I know that catching Exception is a bad practice by default, but in those scenarios I would rather ask the "is\as" question(s) and handle my exception than wrapping using with try-catch blocks. After all, using should allow elegant code...

What do you think ?

update:
I've posted a ladybug at Microsoft Product Feedback, you can check it out (and vote!!!) here:

http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=f3c7e216-8790-4937-acc0-502848232a9d

Posted by Oren Ellenbogen 
05/05/2006 10:37, Israel time UTC+03:00,     Comments [2]  | 
# Tuesday, May 02, 2006

I have a popup window(calendar control) which contains a drop-down-list with many items in it. The problem occurs when I try to select the year 1930, which is outside of the popup frame:

 

calendarbug.gif

 

This close the the entire popup window instead of selecting the year 1930 as expected (well, I did anyway). I tried to cancel the event from bubbling, to set the height of the select object (doesn't work), you name it !

*btw*: I don't want to change the entire flow or to work with a different window model - to much work.

Any ideas ??

Posted by Oren Ellenbogen 
02/05/2006 03:24, Israel time UTC+03:00,     Comments [1]  | 

My team use the Sql Server 2005 Replication feature in order to synchronize between databases in different enviornments. One of the strange things though, is that the reference to Microsoft.SqlServer.Replication generated a weird "Invalid access to memory location. (Exception from HRESULT: 0x800703E6)" Error. After a quick google search I found this link which offers a nice workaround (this seems to be VS.NET 2005 bug) which worked for several folks out there but unfortunately it didn't work for me. The search continues...

Posted by Oren Ellenbogen 
02/05/2006 09:32, Israel time UTC+03:00,     Comments [4]  | 
# Wednesday, April 26, 2006

In one of our screens we were required to refresh a Modal Dialog window in order to redraw the entire screen. Trying to refresh a Modal Dialog window will resolve in a new window with the same url.

A possible solution is to create a new "container" file (MyContainer.aspx) which will only have an IFrame with the "real" page(MyPage.aspx) in it as src; Your main page (MyMainPage.aspx) will open the "container" as Modal Dialog instead of the "real" page. The trick is that the IFrame can refresh itself so we've created a Modal Dialog which behaves as a normal window. if you need to set the Modal Dialog returnValue parameter you can call "top.returnValue=...." from the "real" page.

The downside of this solution is QueryString delegation - if you need to send a QueryString parameter(s) to your "real" page you will now have to pass it via the "container" file.

Posted by Oren Ellenbogen 
26/04/2006 05:16, Israel time UTC+03:00,     Comments [6]  |