févr. 22

In the project I currently work in, I see a few confusion between the use of UniqueID and ClientID we can do server-side or client-side. So it's time to recall the differences between the two.

If you have a Textbox (runat server) with an Id, let's say "MyControl", you will have

  • UniqueId : ctl00$MyControl
  • ClientId : ctl00_MyControl


  • the prefix (here "ctl00") will vary depending of the nesting of INamingContainer controls
  • "$" is a constant, defined in Control.IdSeparator and that may be overriden in the page itself ot in the web.config file
  • "_" is a constant, defined in Control.ClientIDSeparator (and that may be overriden in control's derived classes)

What does it will generate client side ?

<input name="ctl00$MyControl" type="text" id="ctl00_MyControl" />

So to be brief :

  • UniqueID = HTML's name attribute
  • ClientID = HTML's id attribute

Where the confusion comes from ? Probably from your respective favourite browsers. Indeed you will probably end by doing some JavaScript and so doing a getElementById. The only thing is that IE will be more permissive and will find your control if you do a getElementById(Element's name), but FireFox wil fail.

In a single word : ClientID = HTML's id attribute and so when doing getElementById, you should always give the ClientId.

Tags: |
févr. 21

Damien Pinauldt has found a nice tip a few days ago. This is just a configuration tip but can be usefull when dealing with big projects.

By default, when hitting "F5" in Visual Studio, it will build the entire solution before launching the startup project (meaning it may build non necessary projects that may slow down the launching time). How to correct this ? Just ask VS to build only what it needs !

  • Go to Tools / Options
  • Go to Projects and Solutions
  • Go to Build and Run
  • Check "Only build startup project and dependencies on Run"

And here it is !

Tags: |
févr. 20

Hello all,

we are quite in a rush at job right now that prevent me from blogging. Anyway, I always keep an eye on things I can learn and tonight while I was browsing in the Lutz Roeder's Reflector, I have seen something very interesting.
A few days ago, with Damien Pinauldt, I was wondering how to to detect if a type implements a given interface or not. Of course if we have an instance, this is very simple but when having only a type, I was not knowing how to do that. Here is what I have found and some recall.

1. Let's create some classes for the demo

class MyIComparable : IComparable
   //Implementation omitted
class MyIComparableT : IComparable<MyIComparableT>
   //Implementation omitted

1. With an instance

The "is" operator just do perfectly the job, so no problem here

//1. Let's test our type implementing IComparable
MyIComparable t = new MyIComparable();
Console.WriteLine(t is IComparable);                  //True
Console.WriteLine(t is IComparable<MyIComparable>);   //False
//2. And now our type implementing IComparable<T>
MyIComparableT t2 = new MyIComparableT();
Console.WriteLine(t2 is IComparable);                 //False
Console.WriteLine(t2 is IComparable<MyIComparableT>); //True

2. With a Type

First "difficulty" : we need to create a "Type" object holding each interface we want to test. Here the typeof operator and the MakeGenericType will help us.

//Let's create Types variable
//MakeGenericType will help us creating the type 
//by defining what the "T" is
Type myIComparable = typeof(MyIComparable);
Type myIComparableT = typeof(MyIComparableT);
Type iComparableT = typeof(IComparable<>)
Type iComparable = typeof(IComparable);

Now let's compare easily !

//1. Let's test our type implementing IComparable
Console.WriteLine(iComparable.IsAssignableFrom(myIComparable));  //True
Console.WriteLine(iComparableT.IsAssignableFrom(myIComparable)); //False
//2. And now our type implementing IComparable<T>
Console.WriteLine(iComparable.IsAssignableFrom(myIComparableT));  //False
Console.WriteLine(iComparableT.IsAssignableFrom(myIComparableT)); //True

And when I remember I was dealing with the GetInterface or GetInterfaces method. Much simpler like that ! Pretty cool no ?

Tags: | | | |
févr. 10

Hello All,

regularly, I speak about trainings that occur in my company, given or organised by myself.

This list is now published here! You will find :

  • The list of speakers and the different trainings they have given
  • The list of trainings, with the agenda detailed
  • And finally a short explanation of the different kind of training we are giving, and how they will differ (content, length, resources, ...)

If you are interested in an upcoming event, or if you would like to have more information about a past event, do not hesitate to contact me, by leaving a comment !