Loading a Web User Control dynamically is rather easy: MyUserControl muc=(MyUserControl)Page.LoadControl("MyUserControl.ascx"); As a side note, I use this with AJAX, to load a user control, extract the rendered HTML and return it to be added javascriptmagically in a panel on the page.
However, when trying the same piece of code on Visual Studio 2005 with NET 2.0, I got numerous errors that MyUserControl was not found (The name 'MyUserControl' does not exist in the current context). Look, you moron, it's in the solution!! Anyway, I searched the web and discovered that even if I do load the web user control dynamically, I should also add a <@ register..> tag to the aspx, as if I would have the user control on the page.
Easiest way is to move the user control on the page, copy the register tag to the clipboard, undo the user control insertion, paste the register tag back.

Yesterday I had this problem where I needed to access the Session object from a webcontrol. I used HttpContext.Current.Session, after checking is HttpContext.Current was null. Then I've encountered a problem where HttpContext.Current was NOT null, neither were the Application, Response, Request and Server child objects, but Session was null.

After half an hour of searching on the web, I've decided to drill down on the problem and see what were the conditions under which it appeared. It seems someone had used the control in a UserControl that was loaded in the member declaration of the page. In other words, my WebControl was trying to access the Session object inside the constructor of a page. Apparently, the Session object is null in the constructor. Don't use private MyObject obj=new MyObject() anyway, since it breaks the separation of declaration and code, and don't try to access the Session object in the page Ctor.

My solution, after changing the offending piece of code, was to also change the WebControl to check if Session was null and if so, work without it. I also added a Debug.WriteLine('you are an idiot') message, for anyone encountering the same problem.

What can be better than a rant on IT matters? Yes, ladies and gentlemen, VS2005 sucks! Compiling anything takes twice the time it took before, loading it takes 3 times as long as VS2003, resources used are also doubled.
This is not something unexpected from Microsoft, just check out the evolution of the Windows operating system, doubling in size like following a sick Moore law, but this is a developer tool, it is supposed to enhance productivity. I don't even know what I would do without ReSharper.
They also had this idea, which I think it's not bad, of trying to make VS an universal platform for any developer tool. This makes sense if you consider it all started from Visual InterDev. However, if this is not done with the limited resources of developers in mind, it will only annoy people. Who cares Visual Studio 2005 can integrate the team manager stuff, the code, the html, the css, the sql, if I only want to make a small console application and I have to wait 5 minutes for my handy tool to start? It sounds a lot like Weird Al Yankovic's It's All About the Pentiums.

and has 0 comments
Yeah, baby, the World Sucks series is back with a new season. This episode is about smokers and, yes, they suck. And this goes beyond their obsessive need to put something long and slim in their mouth and suck on it.
Smokers suck for only one true reason: they don't care. Everyday I am exposed to tobacco smoke and none of the people that are actually smoking seem to care that other people have to breathe that foul smelling odor. When I go to work on my way to the subway, when I get back home, on the subway stairways (yes, don't wait another 20 seconds you fucking junkies, light the cigarette right in front of me on the conveyor stairs!), in my own home when I open the window and some neighbour decided to smoke the very next window.
I admit, smoking inside your own house should be ok and if the wind brings the smoke into my home, well, it happends. But it's just the last drop in the bucket, is there no safe place? I now understand the glue sniffing beggars that retreated in the subway to live an underground life; it's the only safe haven.
So there you have it: smokers suck, and it is so obvious to me that I don't even feel angry anymore. The only thing I can associate smoking with is farting. Someone farts, the others have to smell it. But who in the world sympathizes with a person that enjoys the smell of their own farts?

Getting back to programming, I am starting a small, but premiere project for Palm. These devices seem to be the work of the devil. The particular model I am programming for is something with a resolution of 240x320, with 64MB storage AND memory and with a 300Mhz processor.

Why?! When all computer screens are rectangular, with the width larger than the height, they make a device that is exactly the oposite. I mean, I understand they are meant to be hand held and all hand held devices are longer than they are wide, but it's still annoying.

Also, if I try to find a PC memory that is less than 256MB I would probably be forced to buy it second hand, yet they make a 64MB model? This also applies to the processor. Are they spending more money to make slower processors or is it just me seing things wrong?

Anyway, I found that working with DataSets in this environment is just awful. I started with a simple test project, 20000 rows in a 3.5MB XML file, loaded into a DataSet then displayed in a datagrid. First, the whole thing went out of memory and froze, then, when I fixed the memory problem by creating my own binary format and loading the file my way (oh yeah, I can see the roots of a XML sucks rant) the datagrid was very unwieldy.

Therefore I devised a ClusterGrid, something that shows clusters of rows in a datagrid and you just drill down and up on it. On my data, finding a customer in a 20000 rows table is 4 clicks away. First it shows 10 rows, representing clusters of 2000 people ordered alphabetically (ex: first cluster, from Alice to DeeDee). You click (or press with the finger, I have no idea how an actual Palm functions, I am using the emulator in Visual Studio 2003) on a cluster, you get another 10 clusters, with 200 people each. Then 20, then 2. Four clicks. Works like a charm. It seems a better deal than the scroll of the datagrid and I wonder why I haven't seen this before.

A small tip regarding the Palm Emulator. The default configuration is set on 32MB of memory+storage. If you want to at least have a functional program, increase it in the VS options, in the Mobile Devices tab. I couldn't make it larger than 64MB for whatever reason, but I never needed more and 32 is way too low.

and has 0 comments
Rant alert! This time I am not sure what or who sucks, so I'll just ask the questions and let you figure out the answers.

Today, in Bucharest, a gay parade was kept to celebrate the removal of article 200 from the Constitution, an article that made homosexuality illegal. Of course, right wing, religious, or just plain conservative people held their own demonstration and todays gay parade was attacked and ended in violence.

That made me think of this gay thing. It never occured to me that it was an issue. Lately, though, I am seeing it everywhere, from movies like Brokeback Mountain and New York style films to scientific reports that say 1 in 10 people is gay. That means that somewhere in my highschool class there were three gay people, for example, and I know of none.

I have no gay thoughts and I might just as well admit a little homophobia. But would I mind seeing people expressing their homosexuality in public, for example? I am sure some instinctual disgust would appear, but I am human, I should be able to get above my instincts. Besides, homophobic feelings, as strong as they may be, they can't be stronger than a persons sexual orientation, can they? Why should these people be forced to fight their own emotions?

On the other hand, another part of me protests violently. I don't want to see men French kissing on the street, touching their bottoms with their hands. I want things to be as they were, I like them like this. Yet, things were not very different for kissing boys and girls a few years ago. Romania being a conservative orthodox society, with a lot of people outrooted by communists from their homes in the country to come to the big industrial cities, young boys and girls showing physical affection for each other were frowned upon. I can remember how mad that made me feel.

Where do we draw the line? It is a weird line, I can tell you that. A lot of things can be seen in public in Romania. Dirty smelly beggars for example, roaming the transport system (for free I might add, while we pay the fare); loud music in the night from people listening to it on their powerful car stereos; extremely annoying comercials, people with flyers or cars that play very loudly some radio music to make you pay attention to the slogans on their sides. So why not gay people? I would certainly like to be in a bus full of kissing men than in a bus of smelly sick beggars.

A few minutes ago an idea came to my mind. Maybe people aren't against homosexuals, maybe it all started from a misunderstood word. You know when you're all lonely and depressed and you see people being happy and together and you feel a strong feeling of anger and annoyance? I think that in all countries people are mostly unhappy. Therefore, as democracy has it, in the early history they forbid gayness. People were not allowed to be gay in public, it made depressed people even more depressed. Then homosexuals chose the word to represent them and it all got mixed up.

So, my conclusion is that to be gay means nothing to me. I can live with the level of annoyance gay people might produce in me and I think they should do whatever they want and be able to express themselves. But then again, I think the same thing about right wing activists, fascists, communists and arab terrorists. Free speech should be truly free, and I would extend this to free expression.

I got it! Laws against freedom of expression suck! They might be gay, also :)

This is a nice link about how to convert a UserControl to a WebControl.
Convert a Usercontrol to a WebControl - The Code Project - ASP.NET

Of course, afterwards it is best to take the time to really think the WebControl through, but for quick conversions like "I want a web control that has a datatable and a graph and another that is a textbox and a validator" it is perfect. Haven't really tested the result on real life user controls.

I don't count myself as a web developer. Maybe what I'm saying here is really basic, but here it goes.

1. CSS Style Sheets are good. Because you can change a lot from the file without changing the site. One could even imagine a complete site makeover only from the style. Remember that style can have color, font size, div position, borders, anything one can think of and it's not in Javascript :)

2. As a corolary to the first rule, style tags and color attributes and stuff like that inside the html file are NOT good. A colleague of mine has submited the idea that there are exceptions to this, like horizontal alignment in table columns and similar basic things. But I say NO! :) If there was a requirement for a certain column to be aligned differently, then it belongs to another style class, even if it's only one column in a thousand columns with the same alignment. I do admit that it's difficult and annoying to copy all the attributes of a class to another just to change something as trivial as the text color. Which brings me to point 3.

3. You can't nest or inherit CSS classes, which is really dumb. I mean, I want a base class to contain text font and color and everything and I want to create another class that says "I am like class1, but with bold font". You can't do that as far as I know, but you can combine classes. An element can have a class="redFont blueBoldFont" which will combine the two CSS classes, and they will overwrite each other. In this case the font will be blue and bold, as the blue color will override the red.

4. CSS classes can be selective. For example .redFont td { color:red; } will apply only to table cells within elements with the redFont class. That is different from the td.redFont notation, which tells what will happen with table cells that have the redFont class. I would suggest avoiding this type of notation if possible. Also, one can somewhat separate the behaviour of a class inside another class: .redFont .blueBoldFont { color:magenta; } in a css file or within a style tag will signify that the blueBoldFont class within the redFont class will have magenta color. Everything else being a combination of the two mentioned classes. This is a little akward, but it works. Warning! the notation .class1.class2 works in Internet Explorer only. The proper notation is the classes names preceded by a dot and separated by spaces.

5. One cannot configure custom html attributes or javascript events in style. That is a hinderance, but I don't know if adding it would have helped things. I mean, I do want to configure all the elements having a draggable class to have special mousedown and mouseup events, but this can also be done from javascript.

What does this mean? It means that a well designed site will have ALL the styling, even the position and size of movable elements, in a CSS file, as it will have all the Javascript in a JS file. This kind of file separation insures that the styling can be changed independently from the Javascript code and the HTML source. It also means that when designing a Web Control, creating a complicated style system for all its elements is not necessary. Just give a default class to each pertinent html element and then give the entire control a single configurable CSS class. Then combine classes to style each element.

Use this in a Javascript event handler to stop the event from continuing. Some events cannot be stopped, but the ones that can will be stopped by this in any browser.

function murderEvent(evt) {
evt.cancel=true;
evt.returnValue=false;
evt.cancelBubble=true;
if (evt.stopPropagation) evt.stopPropagation();
if (evt.preventDefault) evt.preventDefault();
return false;
}

and has 0 comments
I spoke about it in a previous post and I realised that this is an important issue, not just a side note. I never learned about it in school, nor did a lot of my friends. I've researched it and I found out that it's not in the American history books either. It's not even Spanish, it came from the US, and as Spain was not in the war at the time, they didn't have war time censorship and talked freely about it. That's why it came to be known as Spanish. Funny enough, in Spain it was called the French Flu.

But what was it? How did it happen? Apparently it was a type of avian influenza, just like the one we panic so much now, it emerged in an American military fort, then it spread as the soldiers were moved from place to place. When they came to fight in Europe, it spread there as well. The effects are very swift destruction of lung tissue which causes the patient to drown in his own fluids and the flu affected more the young and the fit, not the old people.

Opinions are divided, some say as much as 100 million people have died, while others give a more conservative value of 40-50 million. Compare that with the 16 million people killed in the entire World War I which just ended, and you realise the magnitude of the issue.

So, again, why have so little people heard about it? It is a horrible disaster, yet it is treated as a historical side note. I haven't heard of one movie that used it as a script idea. What is going on? Was the "war time censorship" so efficient? But then why did it not emerge as a huge thing afterwards?

As a history drive it was extremely powerful, for example US president Wilson who negociated the end of the war had it. Maybe if he had been stronger mentally, he wouldn't had let Clemenceau, the French counterpart, have his way in imposing harsher conditions on Germany. That, in turn, could have reduced the German motivation for starting World War II.

Even more interesting is how the disease disappeared. They didn't really have a cure for it, it just vanished, after killing so many. The mortality rate was rather small, too. The new avian influenza has a 66% kill ratio in humans so far.

and has 1 comment
Making a Web Control is not complicated. but things get weird when they need to postback values. Well, how does a Web Control postback? It implements the Interface IPostBackDataHandler which exposes two methods:

public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
public void RaisePostDataChangedEvent()

RaisePostDataChangedEvent should be called by LoadPostData, so you can just ignore it if you don't need it.
LoadPostData will not be called unless the WebControl is registered with the page for postback. I do this in the override of OnInit:
if (Page != null) Page.RegisterRequiresPostBack(this);
postDataKey is the "identifier" of the control, meaning that weird UniqueID with ":" instead of "_" separating the parent control ids from the children. You can use it or not.
postCollection is the Request.Form collection, The collection of all incoming name values.

example, a Label that also adds a hidden input field and handles the postback of that field value. Try changing the value from javascript and the text value will also change on postback.

public class UselessLabelPostback:Label,IPostBackDataHandler
{
private bool changed;
public bool Changed
{get { return changed; }}

protected override void OnInit(EventArgs e)
{
base.OnInit (e);
if (Page != null) Page.RegisterRequiresPostBack(this);
changed=false;
}

protected override void Render(HtmlTextWriter writer)
{
base.Render (writer);
HtmlInputHidden hih=new HtmlInputHidden();
hih.ID=this.ClientID+"_hiddenField";
hih.Value=this.Text;
hih.RenderControl(writer);
}

public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
string s=postCollection[this.ClientID+"_hiddenField"]; //not using postDataKey
if (s!=null)
{
s=HttpContext.Current.Server.HtmlDecode(s);
if (s!=Text) RaisePostDataChangedEvent();
this.Text=s;
return true;
}
return false;
}

public void RaisePostDataChangedEvent()
{
this.changed=true;
}
}

Important:
This is a control inherited from a Label, that's why I chose to render the hidden input manually. This has a few side effects. For example, the id of the label will be ucIPostBackTest1_UselessLabelPostback1 if the control is inside a User Control called ucIPostBackTest1. The id of the hidden field will be ucIPostBackTest1_UselessLabelPostback1_hiddenField only because I used the ClientID of the label when I manually set the field ID. For the same reason the name (the name attribute of a html item is the one that gives the postback identifier, not the id) will be the same.

The way to do it when starting from scratch is to add extra controls in the CreateChildControls() overriden method, use EnsureChildControls() in the PreRender or Render methods and the web control will render them all. Here the names and ids of the rendered child controls will differ and this is where the postDataKey comes in. But that's another story.

and has 0 comments
Third episode from the internationally acclaimed series World that Sucks.
Normally, the good hearted person that I am (yeah, right) would flinch at the idea that 6 million people were moved to special extermination camps and, well, exterminated. But when we talk the Jewish Holocaust, I just can't feel anything. They whined and continue to whine so much about this, that it lost all appeal. That they do almost the same thing with Palestinians is just the tip of the iceberg.
What offends me even more are the number of Hollywood movies and other types of popular shows that are shedding crocodile tears over this. OK, it happened. More atrocious things also happened. A lot more Russians died in the same war, does anybody cry for them? No, they were communists, fuck them! 50 million people died in the Spanish Flu pandemic. Do we hear of it anywhere else than on Discovery Channel? No.
I bet the whole Holocaust Hoax idea came from some guy that couldn't take it anymore. So much bullshit was thrown that it was impossible for any of that to be true.
So my conclusion is that the Holocaust sucks. Any mention of it, as a corollary of the Goodwin law, should end any conversation and disqualify the guy that used it (phew, good thing that this is a blog). And what is even scarier is that after a few years we'll start seeing movies about the Muslim Holocaust in Guantanamo. And if they follow the same pattern, we'll never stop seeing them. Man, that would really suck!

and has 0 comments
For a sneak preview of C# 3.0 a good starting point seems to be:
Future Versions

All the rows in an HTML table have a property called rowIndex, which is the actual index in the rows array. Table cells are in a similar situation with their property cellIndex. BUT, Internet Explorer chooses to interpret cellIndex as the VISIBLE index, rather than the internal one. Netscape, Mozilla and Opera do not exibit this behaviour. Funny thing, the rowIndex works in IE no matter how you hide the rows.

More detailed, style.display='none' makes the cellIndex of the next cells to decrement, while style.visibility='hidden' does not decrement the cellIndex, but keeps the formatting of the page, so you actually see a big empty space where the cell used to be.

I wouldn't have mind this if the Microsoft guys used another index to show the internal value, but they didn't! I have no idea what is the internal index of my cells anymore! Grrr!

and has 0 comments
Except the obvious one that override cannot be used on methods not declared as virtual, there is the little nag of how the original object will use the method internally. Mainly it will use its own not overriden code, but not the methods that hide its code.

Object A has a method M virtual. B inherits A and overrides method M.
With an instance of B, B.M() will run the code in object B, while M() inside the code of object A will also run the code in object B.

Object A has a method M not virtual. B inherits A and hides method M with a new M method.
With an instance of B, B.M() will run the code in object B, while M() inside the code of object A will run the code originally in object A.

Ex:

public class PrintStuff
{
public PrintStuff() {
PrintMe();
}

public void PrintMe() {
Console.Write('ME!');
}
}

public class PrintStuff2: PrintStuff
{

public new void PrintMe() {
Console.Write('new ME!');
}
}

a code like new PrintStuff2(); will output ME! while a code like new PrintStuff2().PrintMe() will output new ME!