Ryan Ternier

Killer ASP.NET ninja coding monkeys do exist!

January 2008 - Posts

Why I love Javascript, and Ie7 hates extra ,'s in prototyping

I've been working with javascript rather heavily for the past few... many months. Years ago when I started working with ASP.NET I was naive and thought everything should be done server side. I thought that the server should do all the work so the clients computers would be able to work fast.  It took only 1 year for me to turn that thinking around.  JavaScript rocks! 

ASP.NET AJAX works great with JavaScript.  You can point to a web service (in your current domain), get the data you need,  and do all the XHTML/HTML Markup changes necessary without a postback to the server. (yes some postbacks are evil)

So why do I love JavaScript? Aside from the Asynchronous nature of it (which can really screw with your mine sometimes), it makes the client computers do the work, and takes the load of your servers. It might be easy for your server to render a DataList of 100 rows. However, if you need that list updated every 10 seconds with the newest data, your server will start complaining when 1000-10,000 people are viewing that page.  You could cache the data, but you'll still be rendering the DataList in your presentation layer.  With JavaScript, you can create a simple object (note JavaScript is not an object based language, you use prototypes... but for the simple eye they look like objects) that can do this for you:

DataItem = function(data)
    this.UserID = data.UserID;
    this.UserName = data.UserName;
    this.FullName = data.FullName;

DataItem.prototype = {
    toString = function()
        return '<div class="detail">UserID: ' + this.UserID = ', UserName: ' + this.UserName = ', FullName: ' + this.FullName = '</div>';
    test = function()
        var d = "test";
        return d;

When you get the results back from your webservice, you can loop through them, creating this object (yea yea) from the data returned, and easily output the data you need.  Very simple, and you have full control. You don't need to rebuild your application if you want to change how a simple list works.

This is where I left off last night with some script I was working on. I get to the office and I began testing it again, pulling my hair out.  FireFox was working fine, however IE7 was blowing up. I kept getting "<custom object> is Undefined".  After creating a few test prototypes I found the culprit... the trailing "," in the last function of my prototype. IE is expecting there to be a new function, FireFox ignores it.

JavaScript is strict, and I love it!

Posted: Jan 31 2008, 10:04 AM by Ryan Ternier | with 3 comment(s) |
Filed under: ,
CSS - Sprites?

Web Designers are always trying to find new and innovative (read:easier and better) ways of creating web sites. Today I stumbled across two sites that really push this.

Remember back in the VB 6 days, or even the C and C++ days where you used Sprites? If any of you ever looked at old NES, SNES emulated games, you would see the graphics were all sprites.

Now you can do this with CSS... well you've always been able to do it, but now it's been shown to really work.  Take a roll-over button for example. Instead of creating 2-3 images for this roll-over, why not have 1 image and you just use a bit of CSS (pseudo classes)  and you're done. This is explained on WellStyled.com very well.

Another great example of this was found on A List Apart.

Gone are the days of creating massive images for everything. Aren't the old ways always best?

Posted: Jan 17 2008, 11:13 AM by Ryan Ternier | with no comments |
Filed under:
More Posts