.NET Discussion

.NET Issues, Problems, Code Samples, and Fixes

ASP.NET: Rethinking Inline Scripting


I came across an article called Crazy Talk: Inline Scripting and Code-Behind and it really made me rethink the way I program. The article discusses how the “taboo” of inline scripting shouldn’t really be taboo anymore because, if done responsibly, it can be extremely effective in cutting down code. As a sort of experiment/form-reuse, I took a working form from one project to implement in a new project I’m working on and tried using inline scripting where it was required.

I was basically blown away by how much simpler it was to just use <%= %> for implementing little things, such as name, address, etc. rather than having to deal with literals on the code behind. The codebehind was cut from 58 lines to two—four if you count the declaration of objects to use for binding the UI—and the same exact result is achieved. I don’t think my codebehind was messy either, just a lot of string concatenation and setting literal .Text properties.

Don’t take this as a license to completely rid yourself of codebehind pages and go nuts building everything into your .aspx page. Server side coding still has its purpose and is still more powerful than inline scripting, and many things are still easier to do on the server side. Just don’t think that it’s still “bad practice” to weave inline scripting into your source code. When used responsibly, it can make a lot of things a heckuva lot easier.

Advertisements

October 16, 2007 - Posted by | ASP.NET, Tips & Tricks

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: