2

jQuery is more than animation

by Jeremy 30. April 2009 16:51
jQuery is all the rage these days with website development.  It seems that a good amount of demos out there just show its flashiness and ability to provide animations.  However, there's a functional side of jQuery that should not be overlooked.  Here's a simple example that can be useful on every web page that collects user input.  

The usability of web forms (forms allowing data entry, not asp.net web forms) can be enhanced by putting the focus on the first input field in the form.  ASP.NET developers often perform this task using server-side code (e.g. txtFirstField.Focus() called in Page_Load).  Using jQuery, you can apply the following script to any web page that has input fields.  Apply this script once across your site and eliminate the need to put the focus on specific fields on each individual page.

$(document).ready(
    function() {
        $("input:text:first").focus();
    }
)

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

jQuery

2

Avoiding dynamic sql - a simple case study

by Jeremy 19. February 2009 14:40

I recently encountered a case where I needed a sql result set to account for the value of an "Include inactive" checkbox in the UI.  The business requirements were: 1) If the user doesn't check the box, display only active records, 2) If the user checks the box, display both active and inactive records.  The active field was a bit in the database table, so all records were either active or inactive.  My first thought was that for case 2, no WHERE criteria would be necessary for the sql statement, whereas case 1 would require "Active = 1" criteria.  This seemed to point to the need to dynamically construct a sql statement based on the inclusion/exclusion of that where clause.

I was working with an existing parameterized sql statement, so really didn't want to switch over to a stored procedure and start dynamically building the sql within the sproc (not to mention building the sql dynamically isn't the cleanest approach to begin with).  After a little thought, I realized that I could solve the problem within the same parameterized sql statement simply using IN criteria. 

Here's a stripped down version of the sql. The @IncludeInactive parameter comes from the checkbox value

SELECT UserName FROM Users WHERE Active IN (0, @IncludeInactive)

Case 1: Checkbox not checked, don't include inactive users

SELECT UserName FROM Users WHERE Active IN (0, 0)

Case 2: Checkbox checked, include inactive users

SELECT UserName FROM Users WHERE Active IN (0, 1)

Nothing ground-breaking here, but much less code to maintain and a lot cleaner than dynamic sql.

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

SQL

0

Software Maintainability: Balancing "correct" vs. "maintainable"

by Jeremy 11. December 2008 14:40

All software developers have been there.  You’ve started a new job, inherited legacy code, or been chosen to support an application for which you have not written a single line of code.  You spend hours perusing the code, trying your best to interpret the brain patterns of another developer, as laid out in source code.  “What were they thinking?”  “Why did they use a property there instead of a method?”  “What the heck does this ‘RunProcess’ method do?”  “What is this ‘aXList’ variable used for?”  It is under these conditions that you really begin to see the importance of maintainable code.  Or, consider an even simpler scenario, where you are the developer and the maintainer.  I’m sure I’m not the only one who has looked at my code a month or two after writing it, and not even realized that I had authored it.  When this happens, you’ll be glad you wrote your application in such a way that it is easily understood. 

Read more in the following whitepaper...

WhitePaper-SoftwareMaintainability.docx (138.87 kb)

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Software Maintainability

Powered by BlogEngine.NET 1.4.5.0
Original Design by Laptop Geek, Adapted by onesoft