Client-side scripts do it faster

by javery on August 17, 2007

I started on a new project recently and unlike most of my previous work this isn’t a new application, but rather an existing one that needs some serious cleaning up and re-working. For the moment we are fixing all the functional issues and trying to clean up what we can, over the next couple months we will be making some bigger changes and improvements.

I have become a firm believer that re-writing from the bottom up probably isn’t the best solution for most applications. Taking it bit by bit and re-factoring as we go is definitely working out well.

I was re-working some javascript to work in Firefox (hint window.showModalDialog is IE only) and found this little nugget of crap on the server-side event of a button:

protected void btnUpdate_Click(object sender, EventArgs e)
{
string script =
string.Format(
"openDialog('url={0}','','Width=450,Height=225, resizable=1,
scrollbars=1, directories=0, menubar=0, status=1;')"
, someID);
Page.RegisterStartupScript("Update",
string.Format("<script>{0}</script>", script));
}

So instead of putting this on the onclick event on the client-side, it does a full post-back and writes the script out. Not only is it an unnecessary request (bad performance), its slower for the user (bad usability), and on top of that it will be blocked by most pop-up blockers (just bad).

For some reason I think I will have more of these posts ahead of me.

-James
P.S. This was posted from Textmate, how cool is that?

{ 3 comments }

Kevin U August 18, 2007 at 8:51 pm

My favorite is a linkbutton, that when posted back it does a response.redirect, anyone every hear of just using a link?

Kris August 19, 2007 at 4:06 pm

Hi James, I’m facing a similar project possibly, and may be coming in to retool an existing ASP.NET application that was poorly received by it’s user base on account of performance and usability concerns. The temptation for most developers is to dismiss what’s there and start on a rewrite. I’d certainly like to avoid this if possible. I’m wondering if you’ve collected any favorites in terms of ASP.NET best-practices, etc. that you feel benefit in this sort of scenario.

For instance, I know you came off of a large ASP.NET application a while back. I’d welcome comments on testing ASP.NET applications, implementing MVC given the somewhat (I feel) lack luster design that the traditional page model encourages. Any info is appreciated, even if only a collection of links on delicious or something.

Take care!

Steven Harman August 19, 2007 at 8:10 pm

>> This was posted from Textmate, how cool is that?

I hate you, and your MacBook Pro!

OK, so I don’t hate you, I’m just extremely envious. But that will all come to an end in October when OSX Leopard is released and I finally order my very own MBP.

But until then I hate you for rubbing it in. :)

Comments on this entry are closed.

Previous post: Books: Less than Zero by Bret Easton Ellis

Next post: Cool Job in Cinci