Monday, December 22, 2008

The IE6 AntiPattern

This might be a little behind the times but it’s still not uncommon for me to spend half a day or more just trying to fix CSS for IE6.  I was reminded of this while reading Joel Spolsky’s blog recently where he said

"I’ve been debugging the new site. The first problem: hopelessly messed up rendering on IE6. The best way to fix CSS problems with IE6 is to generate random mutations on the style sheet until it looks fixed. That’s really the only way to approach these kinds of things; CSS is nondeterministic, and many better minds than mine have gone completely stark raving mad trying to understand the rhyme and reason of IE6 rendering bugs." - Joel Spolsky

My method is not too different from that of Joel’s.  I know the hacks of putting a “#” before the class name or wrapping the entire CSS in “”.  But these are ridiculous work-arounds… and the amount of time wasted…  I wonder if the additional costs of maintaining MSN, Live, MSDN, Microsoft.com, etc. for IE6 outweigh the expense of…

Allow me to digress.  Just the other day my uncle mentioned that he wanted to upgrade his version of Windows XP from the Home Edition to Professional  The reason is that Microsoft was going to stop supporting the Home version soon.  My uncle is the type of person that I would consider an average user.  He uses his computer for managing his photos, email, and the like – nothing fancy.  Because of people like my uncle, I’m pretty sure that IE6 isn’t going away any time soon.  And with IE 6 still at 20% of the market share, it’s a browser that we all have to support.

As far as I know, there isn’t much we can do about the situation except wait it out.  Hopefully with IE 8, Windows 7, and limited support for Windows XP the usage of IE will eventually end. 

And since we’re all complicit, we should also be thinking about how we got here (like the frog in the pot) and how we can make sure that this does not happen again.  I know the story conventional story line that IE 6 was “The Browser” at the time and so whatever worked on IE was correct.  Then came Firefox and it was back to trying to support two different browsers.  Then came IE 7 which was “broken” because it was “fixed”.  And now with the plethora of options (Safari, Opera, Chrome, etc.) we have our work cut out for us.

Friday, December 19, 2008

Isolating 3rd Party JavaScript

I'm looking for a way of protecting our web pages from 3rd party javascript files that might timeout or throw errors. These files are usually for ads where we just include a script reference.



What makes it worse is that these files contain code that does a document.write(). Because of this, moving the reference or trying to load the file asynchronously will cause the ads to be rendered on a different part of the page. Because of the use of document.write(), the only way to load the files without affecting the page's load time is to load them from within an iframe.

In addition, we can override on the onerror event for the page in the iframe.



This method scares me since I really can't imagine what would happen if other developers start putting this little snippet of script into all their pages. In addition this sounds like a whole lot of extra work just because some other companies product is problematic. Stop using their product is what I think.

Tuesday, November 4, 2008

Deep Zoom Composer

Wow!  DeepZoom composer with PhotoZoom is awesome.  Here's my first photo album.  All the pictures are from my iPhone so the quality isn't great.  But it was so easy to make. 

However, one thing is missing.  I'd like to be able to click on a photo and view the original in case I want to print it or send it.  Maybe I'll see if I can add this to the opensource proj.  We'll see if there's time for that.

Friday, October 31, 2008

Sharing User Controls between Web Projects


How many times have you had rearrange your solution or copy code around in order to share user controls between projects? This is one place where Asp.Net is seriously lacking. A user control is supposed to be a piece of functional content that is broken into a separate control for maintainability and code reuse. Why then can I only reuse them within one project?

Well I guess there is one method for doing this by using virtual directories in IIS. So the better question would be why I cannot reuse them easily across multiple projects.

There are some additional steps to make it much easier to actually use these controls as well as access there public properties and methods. Here is the whole process:

1) Create a new web project for your user controls.

2) Create a folder in this project where you will put these controls. (This is not necessary since you can reference the folder of the project but I think that having the user controls folder named the same across projects can make things a little clearer.

3) In a separate web project from where you want to use your shared user controls, create a directory with the same name as the directory from the previous step. (In my example I call this “UserControls”.

4) In the Solution Explorer, right click on this directory and select Add->Existing Item…



5) Browse to the folder in your shared user controls project. Select all the controls along with their code-behind files. But instead of clicking the add button, click the down arrow on the right side of the button. Then select Add As Link.



6) You can now repeat this for any other web projects in your solution. When you’re finished, your solution will look something like this.



7) You can now repeat this for any other web projects in your solution. When you’re finished, your solution will look something like this.

8) Remember to make sure that IIS is aware of your “UserControls” directories as virtual directories so that the asp.net worker process compiles your pages properly.

Enjoy!

Thursday, October 9, 2008

Ctrl+F is changing the way we read

I don’t know about you but I love [ctrl+f] a.k.a the Find command.  Just as copy/paste changed the way that we write and edit text, [ctrl+f] is changing the way that we read.

When I’m browsing a web site in search of some data, I find [ctrl+f] to be the easiest way of scanning the page to see if it might contain the nugget of knowledge I’m looking for.  Especially today when most pages are full of images, ads, and other noise, [ctrl+k] will take you right to the text your looking for.  And you instantly know, regardless of what the Google search brought up, if the page actually contains what you’re looking for.

Visual Studio also has [ctrl+shift+k] which is the short-cut for “Find in Files”.  This allows me to search the entire codebase for any string (or regex) that I’m looking for.  This is great when I need to maintain (read fix a bug) in a part of a system that I’m unfamiliar with.

For example, let’s say that some value isn’t displaying properly on a web page.  Using Firebug I can usually find the control’s ClientID.  This value usually contains part of the control’s ID.  [Ctrl+shift+k] and I can find all the files (pages and user controls) that use this ID.  Then you can find the type, class declaration… and finally fix the bug.


Imagine having this kind tool when reading a reference book.  Sure the table of contents and index are useful.  But just think of how quickly you could find information if you could quickly search the whole book for a word like ListView.




As more and more text based content is available online and we do more and more of our reading online, it will become imperative for any good UI to allow for instant text searching.  That this isn’t already a standard feature in Windows causes a lot of grief.  Just as all text boxes allow cut/copy/paste, they should also allow “find”.  

Tuesday, October 7, 2008

SEO friendly forms in ASP.NET

If you ever need to create a page in ASP.NET that uses some kind of Url mapper, you may run into some problems with posting back. If you look closer, you’ll find that the Url of the request is no longer the SEO friendly one but the actual one (possibly including some querystring parameters if they’re part of the mapping.) And .NET does not make it easy to override the address in the “action” attribute of your form.

The best way I’ve found to fix this problem is to create a Server control that inherits from the standard HtmlForm and overrides the RenderBeginTag() method.



You can now register and plug this new form into any page. You can then set the attribute AllowPostBack to false if there are no postbacks on your page. Or you can override PostBackUrl to set the “action” attribute on the form.

Sunday, June 15, 2008

My first blog

This is my first blog...