Friday, June 16, 2006

Dynamically loading Web User Controls in NET2.0

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.

HttpContext not null, Session null

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.

Thursday, June 15, 2006

Visual Studio 2005

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.

Tuesday, June 13, 2006

Smokers Suck

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?

Sunday, June 04, 2006

Palm PCs

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.

This is gay

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 :)