Tuesday, August 31, 2010

ImageButton Without A SRC Value Causes GET Request!

Situation:

Click submit on a submit button.
Page posts back with IsPostBack == true.
Browser shows page render.

Problem:

Server (in debug mode) shows another request perform, this time a GET, so IsPostBack == false.

Evidence:

An ImageButton was on the page with no SRC attribute at all. This caused the browser (so far happening in (Windows...) Chrome, Firefox and (MAC...) Safari to resolve the URL of the image, for the image button, to be the same as the page the button is sitting on. The request for this then causes a standard GET request to the page and IsPostBack becomes false again.

Solution:

Remove the image button or give it a valid src attribute url.

Result:

Happy developer.

Friday, August 20, 2010

Javascript: Finding All The Properties Of A JScript Object

Just a little function to dump out into an alert all the properties, methods, etc of any javascript object...

function listout(obj) {
var keys;
for (var key in obj) {
keys += key + ' , ';
}
alert(keys);
}

Wednesday, August 18, 2010

Friday, August 13, 2010

LINQ2SQL Exception: The query contains references to items defined on a different data context

When getting the exception
The query contains references to items defined on a different data context.
Check that the context object being used for each 'from' and 'join', etc, within LINQ statements is not a new object but the same one being re-used!

JQuery

A few JQuery links:

Wednesday, August 11, 2010

Reset The Primary Key Of A Table

Lets say you've got 28 rows in your table but because you've been doing a lot of inserts and rollbacks the next key to be inserted is much higher than your highest primary key. This would be a problem if you've done a lot of inserts and have maybe reached the maximum value of the int type being used as the primary key field type.

You would want to reset the index (as all primary keys are special indices) like this:

DBCC CHECKIDENT ({tablename}, reseed, {number})

Don't make my initial mistake and think that the 'reseed' in the middle there is a place holder for a value - it isn't. Just leave it as is; it's a command. The operation is called reseeding, not resetting - but that will be all academic to most of us.

References:

LINQ: NOT IN / NOT EXISTS

So, while trying to get a fairly straight forward (I thought) select ... from ... where ... not in (...) I found that there is not really an equivalent in LINQ, or so I thought...

Read the solution here:
var orphans = (from c in context.Instances
orderby c.Title
where !(from o in context.CategoryInstances
select o.InstanceID)
.Contains(c.InstanceID)
select c).Skip(PageIndex * PageSize).Take(PageSize);

Essentially, the query does the same thing in C# - that is, to get the list of IDs to check within and then check within it for the ID which is hoping to be not found. Because the whole thing is compiled into SQL before before executed, LINQ generates a NOT EXISTS statement in the WHERE clause, rather than the slower NOT IN.

Concept Car Designs

Found this the other day and thought these were all really cool designs, possibly inspired by the forth-coming Tron movie...