Friday, 18 August 2006

Control must be placed inside a form tag with runat=server in NET 2.0

GridView Export to Excel Problems

This guy researched why simple methods like export datagrid to Excel don't work with GridViews or other controls. I have also stumbled on this stupid error when trying to use RenderControl to get the output of a UserControl.

Apparently, the entire problem lies with the
Page.VerifyRenderingInServerForm Method
which throws an exception if the page is not currently in the render phase of page processing, and inside the <form runat=server> tags.

Luckily it can be overridden. Here is the bug posting at Microsoft and their suggested solutions. Microsoft removed the page, so I can't show it to you.

This is the actual code for the method in the Page control in NET 2.0. Just override the hell out of it.
public virtual void VerifyRenderingInServerForm(Control control)
{
if (this.Context == null || base.DesignMode) return;

if (control == null)
{
throw new ArgumentNullException("control");
}
if (!this._inOnFormRender && !this.IsCallback)
{
throw new HttpException(System.Web.SR.GetString("ControlRenderedOutsideServerForm", new object[] {
control.ClientID,
control.GetType().Name
}));
}
}

Representational State Transfer or REST. Is it the new software paradigm or just a big SOA blowout?

Business - Redefining How Software Works

REST (Representational state transfer)

Representational State Transfer

Probably what I am saying here is naive, as I hate XML and don't quite understand the full scope of things like REST, but from what I managed to gather, this system has a few possible advantages: good caching, good division of resources (both computational and data) which should allow for better user in multitask/multiprocessor systems, true native use of XML (or any other format :D), therefore saving a lot of time from serializing, instantiating, deserializing, etc.

If what the first article says is correct, this would prove to be a system both adaptable and scalable, something that programmers seek all the time. It can be spread out on more computers on a net or used on the same computer, with more efficiency and easy of programming than the dreaded web services or SOA.

Personally, I think I wouldn't particularly like programming in a REST way, but one never knows.

Wednesday, 16 August 2006

WinDirStat - Windows Directory Statistics

WinDirStat - Windows Directory Statistics

WinDirStat is a little useful program that creates a graphical representation of one's harddrive. It uses colored rectangles to represent directory structure, file size and file type. You can click on the rectangles and see what the file is, zoom in and out, etc. What's mostly useful for is seeing the big space wasters as large rectangles and being able to identify them. I am still not sure what Unknown space is, but I have 6.5Gb of it.

Tuesday, 15 August 2006

In love with oneself

A good friend of mine was telling me when we were in highschool that people are made out of different personalities, each alive and fighting for control. He called them rather pompously infrapersonalities. They all define you in some way or another and the "you" is not a simple sum, but a warped weighted average.

Taking the reasoning further, I reached the conclusion that the way we perceive other people is also encapsulated in a hostage personality that describes that person. We don't relate to the actual people, but with our projection of them. Of course, that applies to everything, not just people, but it's besides the point I am trying to make.

What if you spend a lot of time defining such a person? Doesn't it mean the associated infrapersonality "gains weight"? It becomes more alive inside you. There is even a disorder when people switch from one dominant personality to another.

But what if you had feelings for that person? Could its infrapersonality remain alive, evolving separately inside you? Of course it could. And then, why can't you retain the feelings you had for that person if it is alive and so close to you?

I end my reasoning here. I completely pass the (important) point that even if you do love a living and existing person it is still a feeling related to an internal representation of that person. At least it gets updated. Can one projection of another person make you continue to be in love with it, in the absence of that person? I think it can. Worse, I think it is happening to me, and that makes me (even more than you possibly thought) in love with myself. Bummer, huh?

End to all stupid wars?

It just occurred to me that the biggest problem on Earth is not war, but the unending talks that come afterwards. Therefore, I propose a UN resolution that bans war. If any country starts a war without being sanctioned by the UN, it is to pay. And pay a lot. No, the answer is not military retaliation or anything, but money. Each unsanctioned war day is to cost between 10 and 100 million EUROs.

The solution is both simple and elegant. If you need to start a blitzkrieg, do it, just make sure to pay afterwards. You want to go to a country, bomb its infrastructure, steal its oil? No problem, just make sure you win more than you pay to the UN. You want to stall the peace talks? Ok, but do it on your own money. You don't agree to pay? Just forget about exporting or importing anything.

Of course, there is a catch. Lately, no conflict was called a war. Therefore a clear definition of it is also required. That would help mentally challenged leaders to use the right words, too. What's my definition of war? Any conflict outside your borders perpetrated by the national armed force.

What about Hezbollah? you will ask. They attack outside the Lebanon borders and are not the official national armed force. They should be off the hook. Yes, you heard me right. Israel wants retaliation, do it with a private force of people payed or otherwise motivated to do so. In other words: pay for it!

And if you don't want to pay, ask the UN, NATO, or any other legitimate international force to sanction your need for blood or solve your problems or whatever. We can't wait for politicians to solve a problem WHILE the problem exists. They move slow, they have no foresight and their hindsight is limited to what helps them look good. Use preemptive measures: any war costs. Don't forget that the military and the politicians are ruled by the same type of people that rules everybody today: suits! The modern name for aristocracy. And they only care about one thing: money!

Monday, 14 August 2006

Accessing Row based data in an efficient and maintainable manner

Accessing Row based data in an efficient and maintainable manner - The Code Project - C# Database

This is a nice and simple article about accessing data from a lot of datarows. While using the string index will make the code more readable, using the integer index will make the code faster. The solution? Get the numeric indexes at the beginning of the loop, based on string indexes. Assert the indexes exist for better debugging. Very elegant. Also, check out the user comments, which are pretty good and to the point.

Code example:

int customerIDIndex = table.Columns.IndexOf("customerID");
int customerFirstNameIndex = table.Columns.IndexOf("firstName");
int customerLastNameIndex = table.Columns.IndexOf("lastName");

System.Diagnostics.Debug.Assert(customerIDIndex > -1,
"Database out of sync");
System.Diagnostics.Debug.Assert(customerFirstNameIndex > -1,
"Database out of sync");
System.Diagnostics.Debug.Assert(customerLastNameIndex > -1,
"Database out of sync");

foreach(DataRow row in table.Rows){
customer = new Customer();
customer.ID = (Int32)row[customerIDIndex];
customer.FirstName = row[customerFirstNameIndex].ToString();
customer.LastName = row[customerLastNameIndex].ToString();
}//end foreach

Add table header on each printed page

How to include a header on each page when printing a DataGrid - The Code Project - .NET

There is a simple solution for printing tables with repeating headers on each printed page. It involves CSS styling of the THEAD section of a table. Unfortunately, neither DataGrids nor GridViews render the THEAD tag. Somehow, Microsoft seems hellbent against it. So either create a control that renders THEAD, then add "display:table-header-group;" to the THEAD style, or use this Javascript function:



function AddTHEAD(tableName)
{
var table = document.getElementById(tableName);
if(table != null)
{
var head = document.createElement("THEAD");
head.style.display = "table-header-group";
head.appendChild(table.rows[0]);
table.insertBefore(head, table.childNodes[0]);
}
}
Update:
Building a GridView, DataGrid or Table with THEAD, TBODY or TFOOT sections in NET 2.0