# Tuesday, 29 August 2006

People that use ASP.NET know that it's very easy to use the Properties pane in visual studio to quickly set some properties on a server control. By default already a lot of such properties are made available but sometimes you just want something that just doesn't come out of the box. Luckely the WebControl class also provides the Attributes property which is of type AttributeCollection. You can use the Add method to add new attributes to your control.

To make it more clear I created a small demo page that I used to answer a question on the ASP.NET forums.

    1 <%@ Page Language="C#" %>


    3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    5 <script runat="server">


    7     protected void Page_Load(object sender, EventArgs e)

    8     {

    9         ListBox1.Attributes.Add("ondblclick", "GetValue();");

   10     }

   11 </script>


   13 <html xmlns="http://www.w3.org/1999/xhtml" >

   14 <head runat="server">

   15     <title>Untitled Page</title>

   16     <script type="text/ecmascript">

   17     function GetValue()

   18     {

   19         box = document.getElementById('ListBox1');

   20         x = box.options[box.selectedIndex].value;


   22         if(document.all)

   23             document.getElementById('Label1').innerText = x;

   24         else // FireFox doesn't implement the innerText property.

   25             document.getElementById('Label1').textContent = x; 

   26     }

   27     </script>

   28 </head>

   29 <body>

   30     <form id="form1" runat="server">

   31     <div>

   32         <asp:ListBox ID="ListBox1" runat="server">

   33             <asp:ListItem>One</asp:ListItem>

   34             <asp:ListItem>Two</asp:ListItem>

   35             <asp:ListItem>Three</asp:ListItem>

   36         </asp:ListBox></div>

   37         <asp:Label runat="server" ID="Label1" />

   38     </form>

   39 </body>

   40 </html>

On line 9 you can see that I add an attribute. In this case the ondblClick javascript event. This results, once rendered in a browser to have the ability to double click on an item and have the selected value set as being the text of the label control. The javascript function that accomplishes this task is on line 19 - 25.

Tuesday, 29 August 2006 19:21:02 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, 28 August 2006

Just got back from vacation and look what Microsoft provides: Internet Explorer 7 RC1. Get it while it's hot.

Grz, Kris.

Monday, 28 August 2006 18:19:08 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Saturday, 19 August 2006

For some projects I like to start with a blank solution and add several projects to it like a class library, web project, ... Since I installed Visual Studio 2005 Team System for Developers a while ago I wanted to go for this approach for a test project. Unfortunately the solution itself dissapeared after adding the first project.

It turned out to be a setting under Tools | Options, Projects and Solutions where you can check the checkbox Always show solution.

Grz, Kris.

Saturday, 19 August 2006 12:32:51 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, 18 August 2006

I've written already some articles in the past about the null coalescing operator (1) but recently my colleague found some "strange" behavior when using this operator. First of all the guilty code:

    1 using System;

    2 using System.Collections.Generic;

    3 using System.Text;


    5 namespace ConsoleApplicationNullableTypes

    6 {

    7     public class NullCoalescingTestWithinObject

    8     {

    9         static void Main(string[] args)

   10         {

   11             int multiplicator = 5;

   12             int workRegime = 6;


   14             SomeObject so = new SomeObject();

   15             so.Test = 7;


   17             decimal result = (so.Test ?? 0 * multiplicator) / workRegime;


   19             Console.WriteLine(result.ToString("N"));


   21             Console.ReadLine();

   22         }

   23     }


   25     internal class SomeObject

   26     {

   27         private decimal? _test;


   29         public decimal? Test

   30         {

   31             get { return _test; }

   32             set { _test = value; }

   33         }

   34     }

   35 }

 The actual behavior for investigation is on line 17. The parenthesis are omitted around the statement so.Test ?? 0. This causes the following code to be produced (I used Lutz Roeder's .NET Reflector tool for this):

private static void Main(string[] args)
      int num2 = 6;
      SomeObject obj1 = new SomeObject();
      obj1.Test = new Nullable<decimal>(new decimal(7));
      Nullable<decimal> nullable1 = obj1.Test;
      Console.WriteLine(((nullable1.HasValue ? nullable1.GetValueOrDefault() : new decimal(0)) / ((decimal) num2)).ToString("N"));

The output is 1.17 and not really what one would expect.

Now with the parenthesis placed around the statement so.Test ?? 0 so line 17 becomes:

   17 decimal result = ((so.Test ?? 0) * multiplicator) / workRegime;

The output becomes 5.83 and is what is expected. Now the following code is generated:

private static void Main(string[] args)
      int num1 = 5;
      int num2 = 6;
      SomeObject obj1 = new SomeObject();
      obj1.Test = new Nullable<decimal>(new decimal(7));
      Nullable<decimal> nullable1 = obj1.Test;
      Console.WriteLine((((nullable1.HasValue ? nullable1.GetValueOrDefault() : new decimal(0)) * ((decimal) num1)) / ((decimal) num2)).ToString("N"));

For developers whom are still new to this new operator you must be aware of the operator precedence in C#(2). The * operator is normally executed before the ?? operator. But in the generated code we can clearly see that the num1 variable, in our code multiplicator, is omitted which causes some strange side effects to your code to kick in.

Grz, Kris.

(1): Testing upon Nullable types in C# 2.0 and Be sure to put in some default value when testing with Nullable types in .NET 2.0.
(2): operator precedence in C#

kick it on DotNetKicks.com

Friday, 18 August 2006 13:30:17 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, 17 August 2006


I'm just testing out Windows Live Writer. A completely new tool by Microsoft, still in Beta but it works already great with dasBlog. You can also extend it with extra plugins (1). It still lacks some extra's but I already like the nice integration with dasBlog. Even the Categories are available.

Update: There are already some nice plugins available on CodePlex: Window Live Writer Plugins, Flickr4Writer and Tag4Writer.
Update 2: It seems another VISUG member also has created a plugin for Live Writer: SyntaxColor4Writer.

Grz, Kris.

(1): windows live writer plugins: flickr and tagging and Write a Windows Live Writer plugin using C#.

kick it on DotNetKicks.com

Thursday, 17 August 2006 18:24:39 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 

Just installed the Beta version of Windows Media Player 11. The new and upcoming version. I like it a lot until now, especially the new button style of Vista. I could only wish that Microsoft decided to have the same kind of buttons in the default, so no Glass or Aero, mode of Windows Vista as well.

Grz, Kris.

Thursday, 17 August 2006 15:52:11 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, 14 August 2006

I got contacted recently by Scott Hanselman, to ask if they could reproduce my recent article on creating custom macros for dasBlog. I agreed and so here it is: http://dasblog.info/2006/08/10/Creating+Custom+Macros+For+DasBlog+.aspx.

Grz, Kris.

Monday, 14 August 2006 17:40:54 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Sunday, 06 August 2006

Because developing with the .NET framework gives you the freedom to use multiple languages it can be a bit of a hassle to choose between them. VB.NET and C# are probably the most wide spread languages and a question that gets asked regularly on the ASP.NET forums is which one to choose. My answer: learn one of them and when you're familiar with one learn the other. My former company used VB.NET as their default language. In my free time I learned C# though so I became familiar with both. The hardest part isn't actually learning another "dialect" language but learning which classes and namespaces there are available to you is.

Well in aid of those who like to know both languages I found a couple of comparison cheat sheets:

And of course some conversion tools:

Grz, Kris.

kick it on DotNetKicks.com

Sunday, 06 August 2006 14:55:20 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  | 
# Tuesday, 01 August 2006

Sometimes you can still get amazed by new programs although we're used of seeing a lot of wow applications already. Microsoft research lab recently introduced a new product of theirs: Photosynth. In this case seeing is believing so here goes:

Grz, Kris.

Tuesday, 01 August 2006 20:53:23 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, 31 July 2006