Monday 29 June 2009

ASP.NET Ajax document.getElementById is null or not an object

This has taken me three days to figure out. For what seemed like absolutely no reason, my ajax enabled application just stopped working. I went back through all my changes to see what it could have possibly have been to make the application start throwing the javascript document.getElementById('') is null or not an object error, and specifically, why it was doing this on document.getElementById('HEAD[0]').

I eventually found a secton of html that I had commented out with html comments, and I had included in this an asp.net ajax tag.

Removing these comments fixed the problem!

Wednesday 24 June 2009

SQL Server Cannot resolve collation conflict for equal to operation.

Today I migrated an exisiting set of tables from one database, to a new database, to isolate their work.

After copying all the stored procs, views, tables and data, one of my stored procs wouldn't run.

Everytime I tried to execute it, I got the error:

"Cannot resolve collation conflict for equal to operation."

It transpires that this error can be caused by many different problems, butt he main one being that the collation types for the columns being joined in the sql statement is different.

In my instance this was not the case, but by telling the columns to use the databases default collation on either side of the join fixed the problem - e.g.

SELECT table1.*, table2.* FROM table1
INNER JOIN table2 ON table1.column1 COLLATE DATABASE_DEFAULT = table2.column1 COLLATE DATABASE_DEFAULT

Thursday 11 June 2009

CompareValidator doesn't fire

I have an application where I am using a CompareValidator on a field that is acting as a CAPTCHA, therefore I am comparing the value that is entered.

When testing the page, I was clicking the submit button on the form, before entering any text, but when I did this, it was submitting the form! Why, when the value couldn't possibly be the same?

The reason for it is the depths of the AJAX js files:

function CompareValidatorEvaluateIsValid(val) {
var value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
var compareTo = "";
if ((typeof(val.controltocompare) != "string") ||
(typeof(document.getElementById(val.controltocompare)) == "undefined") ||
(null == document.getElementById(val.controltocompare))) {
if (typeof(val.valuetocompare) == "string") {
compareTo = val.valuetocompare;
}
}
else {
compareTo = ValidatorGetValue(val.controltocompare);
}
var operator = "Equal";
if (typeof(val.operator) == "string") {
operator = val.operator;
}
return ValidatorCompare(value, compareTo, operator, val);
}

The following line is the culprit:

if (ValidatorTrim(value).length == 0)
return true;

If the length of the information input into the box being validated is 0, i.e. nothing entered, then this validates as true. This means that if you compare something to nothing, that is valid.... stupid, but valid.

The solution to this is to add a RequiredFieldValidator as well, which then forces the length to be greater than 0, an thus makes it all work

Thursday 4 June 2009

Compiler Error Message: CS0115: 'ASP.pagename_aspx.GetTypeHashCode()': no suitable method found to override

I came accross this problem today when converting a set of application pages into master pages.

My initial problem was that I had set CodeFile attribute of the @Page directive, rather than the CodeBehind attribute.

The second problem was that my page was inheriting from the Masterpage, rather than from System.Web.Ui.Page.

When I fixed these it worked.

It essence, if you get this error, check out what, and where your page is inheriting from.

Tuesday 2 June 2009

Outlook 2007 Email Headers

I keep forgetting where to find this one....

When you wish to see the header, right click on the message in your inbox and choose "Message Options". The window that pops up has the headers showing in it.