Nov 17
richardASP.NET
Using jQuery goodies within ASP.NET webpages is generally not a big deal. However, I recently ran into some headaches when trying to get a jQuery method to work from inside an ASP.NET UpdatePanel. And we all want to use as much AJAX in our web apps as possible for the best user experience.
None of the stuff I’m about to present is mine. I got it from here. The problem was that I spent three hours sifting through dozens of webpages with “solutions” that did not work before tracking down the correct answer. Furthermore, when I found this solution, it wasn’t even the solution that was tagged as the correct answer. It was one that was further down in the comments by a user named PongGod. So, kudos, to PongGod!
Anyway, I love it when people take the time to post clear, well-documented, and easy-to-follow solutions. Since this was anything but, I present it to you now for your edification.
The Scenario: You would like to present messages back to your users, but not have those messages stay on the screen until another postback or refresh is called. This can be especially tricky when you are using AJAX because the whole point is that you want to avoid doing complete postbacks.
The Solution: Use the elegant and nifty fadeOut method in jQuery. Here’s how you can do it:
1. Download jQuery to your computer. [TIP: after downloading jQuery, I make a copy of it and give it the generic name 'jQuery.js' instead of the long name with the version number. The Pro is that it makes my code more maintainable. The Con is that it makes it harder to tell what version I have added to my project.]
2. Add jQuery to your ASP solution in Visual Studio. [Right-click your project name in the Solution Explorer pane and select ‘Add..’ >> ‘Existing item…’ >> then find your jQuery.js file. When you are done, it will look like this:

3. Add the reference for jQuery, a javascript function titled ‘dispMessage, and a css style for a class called ‘notify’ to the head tag:

4. Add your ScriptManager and the UpdatePanel so you can AJAXify your web app. Then add your form objects inside the ContentTemplate tag. If this is new to you, here is an excellent, very basic, intro to ASP.NET AJAX that will get anyone going within minutes.
So here is what my simple example page looks like, from top-to bottom:

Lines 9-16 describe a style called .notify. I use this style for the label that I will use to display my messages back to the user. This label is on line 37. I named it ‘lblNotify’ (don’t forget to add the CssClass=”notify” to the label tag).
Line 18 is my reference for jQuery.
Lines 20-25 is the JavaScript function that tells anything using the CSS notify class to display, then it calls the fadeOut method from jQuery. The ‘5000′ means that the fadeOut will take roughly 5 seconds. Feel free to change it.
Cool so far?
5. Create the code-behind for the button that submits your form. Here’s a simple example:

In lines 23-28 you would normally do some data validation checking, connect to a database maybe, and write the form data to the database, perhaps send an e-mail letting someone know that a record has been added to the database. Whatever. Normal stuff.
On lines 29-32 I clear the data from my form so that button-happy users don’t re-click the button and submit multiple records to the database.
Line 33 sets up the notification that I want to display for the user.
Finally, Line 35 and 36 is the single statement that tells the web page to execute the JavaScript function ‘dispMessage()’. The ‘notifyMsg’ attribute on line 36 is just a unique name that you supply for the RegisterStartupScript.
Oh, I also repeated the same stuff in lines 14-17 inside the Page_Load event, just so the user is greeted with a nice instructional message when the page first opens.
6. You are done! Give it a try. Simple, but nice.
Aug 04
richardASP.NET
Often you have your server code perform some kind of task whenever a user changes a field on a web form. But sometimes when the page reposts or refreshes the web form loses focus.
If the form is long, or the user has done some scrolling to get to the field, this can cause confusion as the form resets itself to the top and focus is lost on the field that was just changed and the user is (rightly) irritated.
Efficiency says that you should use JavaScript and not expend a round-trip to the server.
But if you can’t (or won’t) here’s a quick tip to set focus back on the text field that triggered the code-behind method:
In this example you have several TextBox controls and you have created a nice method that gets called on the ontextchanged event for each of them…
Amount:<asp:TextBox ID="txtMatterAmt13" runat="server" ontextchanged="calculate_Total" AutoPostBack="true" Text="0.00"></asp:TextBox>
In the code-behind the method header looks something like this:
protected void calculate_Total(object sender, EventArgs e)
Look at the nice sender argument. We can use that to our advantage!
To return focus to whatever TextBox triggered calculate_Total just add this at the end of your calculate_Total method:
Control sendingControl = (Control)sender;
sendingControl.Focus();
Voila! (or, as they say in the US: “walaa”)
Jun 27
richardInsects, Stuff I've found
At Headquarters we are always excited when there’s a new insect to identify. Of course, by “we” I mean me, but that doesn’t matter.
Mark found this gorgeous creature in our garage, presumably it fell from the grill or radiator of the family minivan. I was excited, but Mark seemed uninterested. So much for the theory that a little scientific curiosity is an inherited trait.

Strange (dead) visitor
I whipped out our trusty copy of An Instant Guide to Insects and initially concluded that this was a European Hornet. At 4cm long by 7cm wide, I think she’s too big to be a Yellowjacket. The only problem is that the range of the European Hornet stops well before Texas, like around Alabama/Mississippi.
I think she is a “Cicada killer”, Sphecius speciosus. I say “she” because it has a stinger and according to the Aggies the males are incapable of stinging, which I took to mean that males don’t have stingers.
I think I’m going see if I can find a long pin and a display box because it is in perfect condition.
Jun 15
richardUncategorized
After 16 years I gave up today:
OLD (and Busted):
function Count(text,len) {
var maxlength = new Number(len); // Change number to your max length.
if (text.value.length > maxlength) {
text.value = text.value.substring(0,maxlength);
alert(" Only " + len + " characters are allowed in this field.");
}
}
NEW (hotness):
function Count(text,len)
{
var maxlength = new Number(len); // Change number to your max length.
if (text.value.length > maxlength)
{
text.value = text.value.substring(0,maxlength);
alert(" Only " + len + " characters are allowed in this field.");
}
}
It just makes it easier to eye-ball misplaced or forgotten braces. Yes, I believe that the first is “correct” (whatever that means), but the second is more readable. Ultimately, if your code isn’t readable you haven’t done your job properly.
Jun 09
richardNews blackout News blackout, Simplify
Well, if you are doing a news blackout experiment like I am and getting the news only through what you hear directly from other people, then you know that the only story of the week was something about a congressman named Weiner who, well, you know by now.
I probably don’t know all the details that someone who has followed this story closely on CNN or Fox News does but I know enough to have learned this important lesson: Assume that any picture of you that is posted to the Internet will be viewable #1) by anyone and #2) forever. If you just make that one assumption, you will be ok.
Other than that, I don’t think I’ve missed much news. Perhaps it’s been a slow week? I can tell you that since June 1st I have probably saved three hours a day (conservatively) by NOT checking in on Flipboad, Zite, Google News, CNN.com, and the local news on TV. Let’s see, that’s three times 8 days… Erm, wow! 24 hours! A whole DAY!!!
Now, I cannot honestly tell you that I’ve turned all that extra time into completed essays, art projects, shipped software, and funny comix posted to Table38.com, but I have sensed the extra whitespace in the recently passed days. Things don’t seem so rushed.
I like that.
Jun 01
richardNews blackout News blackout, Simplify
When I was in college, I had this cool English Professor. He was a hippy. As in the flower-power, Age of Aquarius, Turn On, Tune In and Drop Out variety. He was the genuine thing. This was the Summer of 1984 and I’d have to guess he was about 40 years old, so it all made sense and it was all plausible because he would have been in his twenties at the time. If in doubt, this was at the University of Texas in Austin Texas, which was (and still is, I wager) a major hippie nexus.
On the first day of class he mentioned that he was in the middle of an experiment where he was isolating himself from all new reports from all sources except those of direct accounts from talking with people. The idea was that he would avoid reading newspapers or watching the news for a whole year, gathering only what was important from the perspective of his friends and acquaintances, then sort of catch up after the fact. From the vantage point of a few months to a full year after significant events took place he could then compare his notes of what people thought was really earth-shatteringly important at the time with a somewhat more historical perspective.
For example, the death of Osama bin Laden seems really important right now. Very significant. But when we look back a year from now, will it actually seem like that big of a deal? Conversely, what if something happens today that almost no one takes notice of, but a year from now changes the world significantly?
A side benefit of this experiment, the Professor explained, was that he expected to have more peace and less anxiety in his life because he would no longer get caught up in the “plane crash in India” or the “starvation in Somalia” or whatever crisis-de-jour was going on that we all had no control over whatsoever.
In the years since taking this class, I never forgot this. Man, I love hippies! At the time I thought that this was the coolest idea ever. I’m not sure I was so excited that I wanted to join this great experiment myself, after all I was too busy working towards that business degree, attending Young Republicans meetings, and drinking beer.
Today, and by “today” I mean these crazy, recent years of media saturation brought on by 24 hour news networks and a continuous live connection to the internet, I wonder if my old Professor’s experiment might just be the remedy I’ve been seeking. You see, I love technology. I love computers, I love gadgets of all kinds. I have to have them. But at the same time, I do understand that along with each device… like any possession, comes a bit of responsibility. And a bit of mindshare. And a bit of attention and focus. With each acquisition of, well, anything, comes a price. Not the cost of the gadget, mind you, but a psychic cost.
Let me explain.
The psychic cost is everything that you have to do differently, everything you have to do that is new, everything you have to spend money on that comes as a direct or indirect result of acquiring something new.
Here are two examples:
Let’s say I buy a book. Buying a book is a commitment above just a few dollars. It’s a commitment of time: I’m telling myself that I am going to spent time away from other activities so that I can read this book. There’s a cost-benefit tradeoff here. I might sacrifice sleep, I might sacrifice TV time, I might sacrifice quality time with my family, but something will give so that I can read this book.
It’s not that big of a deal, because eventually I will either finish the book or put it on a shelf half-finished. It may be a commitment of additional expense: I may have to buy another bookshelf.
But then here comes a load of other stuff. Stuff you may not be consciously aware of, but its stuff that will affect you on some level: either awareness or unawareness.
I call this the psychic cost or commitment.
Let me continue with this simple example of a book, then we’ll do another more complex example to help me make my point.
When I buy the book at some level however small I’m thinking:
“When am I going to find time to read this book?”
“Where am I going to put it when I’m done?”
“Can I really afford this book?”
“I really should be cutting the grass right now instead of reading this chapter”
As I’m reading the book, I might be challenged to make a change in my life, which could cause other consequences, worry, or stress. The book might be so good that it consumes my thinking at work when I should be focusing on other things.
Nothing, you see, exists in a vacuum.
Another example: I just bought an iPad2. I just had to have it. Had to. It was so pretty.
Plus, I reasoned, I could replace these cheap ratty composition books that I use to constantly scribble notes and doodles in. With the iPad, my notes would be neat and typed. I could use the Search function to quickly find things… a feature that the 4-for-a-dollar Comp books are lacking in their current version.
I would use the calendar to make optimum use of my precious time. I would use the digital drawing apps to quickly sketch out rough ideas then export them to the iMac and create masterpieces of fine Western art.
Because inside that little iPad was all the promise of a perfect, uncomplicated, stress-free, organized and effective life.
The problem, of course, is that it is all a lie. It always had been. The Newton was a lie. The Palm Pilot was a lie. The Palm TX was a lie. The iPhone was a lie. All of these gadgets should have morphed me into a powerhouse of personal productivity and effectiveness by now but it didn’t. I should be the head of a major corporation by now. Or a Nobel prize winner. Or a bestselling author.
Instead, here’s what the iPad brought into my life:
- I had to buy a cover so the glass wouldn’t get scratched.
- I had to buy a back cover so the device’s case wouldn’t get scratched
- I had to purchase drawing, writing, and list-syncing apps to replace the functionality of the little composition book
- I had to buy a wee stylus to make drawing more, well, more like using paper-and-pencil
- I have to remember to charge the device every other day
- I have to remember to sync it to iTunes every now and then to keep the operating system up to date
- I have to keep the apps I purchased up to date
- I have to keep checking to see if there are any new apps that might make my life better… or at least work better than the apps I already bought
- I now find myself writing more Tweets than ever, I check in on Facebook a lot more than I did when it was just me and the iMac
- I check Flipboard and Zite constantly for new stories and news items almost compulsively
- Ditto for e-mail
- I have become a weatherman… I know the temperature, relative humidity, and wind speed and direction for my area and this data is never more than 15 minutes old. I know what is on the radar
- I juggle dozens of PDF books from and between iBooks, MobileMe, and DropBox and the three computers, iPhone and iPad.
- I think about what the iPad3 is going to be like
- I think about where I’m going to put the iPad overnight. I think about whether or not I should keep it on my desk at work or lock it up in a drawer when I leave my desk
- I’ve lost productivity at work in my attempt to use this device to gain productivity
- I feel bad when I don’t use it to take notes because that’s what I bought it for
- I feel bad when I do use it to take notes because the process is slower and more frustrating than just taking a pencil to my composition book
- I’ve wasted time at home playing around with it
- I have to remember to bring it into the gym with me because it can’t stay in the trunk of my car in this heat
- I think about how I should be using it to increase my productivity and make my life better
- I think about I have failed so far to use it to increase my productivity and make my life better
On the other hand, I have a friend who also bought an iPad2. He uses it to watch Netflix and doesn’t seem to worry about it otherwise. I want to be him!
Have you ever heard of a Cray Supercomputer? Back in the 70’s and 80’s there was this guy named Seymour Cray. He created and built massive computers that were used to model complex equations and systems. I read that Seymour Cray never had a computer on his desk. All he had was a pad of graph paper and something to write with.
I want to be Seymour Cray!
Now, I may have just convinced you that I’m just neurotic and overly prone to navel-gazing. But you have to trust me: I’m just like you. We just worry about different stuff.
I have a lot of tools and gadgets in my garage. I don’t give any of them a second’s worth of thought in any given week. I keep a vegetable garden and it is more fun than a chore even though it requires daily care and attention.
It doesn’t even have to be things that make us pay this psychic cost. I constantly worry about art. I think about how I should be making art when I’m not and I think about the futility of making art when I am.
End result: you buy something that you think will improve your life in some measure, but it probably won’t. In fact, it will more than likely make you more miserable.
So, back to my old Professor and his big News Blackout experiment. I’ve been thinking a lot lately about the concept of how having greater knowledge of certain events may make us more informed, but it leads to greater unhappiness. And I don’t mean this from an ignorance-is-bliss kind of perspective.
So here’s what I’m going to do:
- No more television news, internet news, or any mass media information source.
- I will go back to carrying and using only a composition book, in which I will write and draw whenever I feel like it.
- I will no longer keep a calendar, but I will plan daily and rely on my wife to tell me what our social commitments are.
- Every day I will think of three things I want to accomplish and I will do them. After they are done, I will think of more things I could do and I might actually do them.
- I’m going to begin to sell, give or throw away a lot of my stuff
- I’m going to quit worrying and quit getting anxious over things and events which are beyond my control.
- I will blog about it, just in case anyone is interested, but the blog will primarily be for my own record-keeping or diary.
I’m going to do this for one full year, starting today. June 1, 2011 through May 31, 2012.
Join in if you like.
Now, I’m going to get started.
May 01
richardStuff I've found
Found this in a Parking lot near Commerce Street and S. pearl Expressway

Oct 21
richardASP.NET
With ASP.NET forms there’s always a button (usually your Submit button) that is enabled when the form loads. This sets up a potentially undesirable situation where the user completing a form may press the Enter key and cause the form to be submitted before they were really ready to do so.
You’d like to be able to disable the Enter key.
Here’s one solution that I found here after searching and trying several other methods.
Add the following code somewhere inside your script tag, you can name your function any thing you want:
<head>
.....
<script language="JavaScript" type="text/javascript">
<!--
function stopEnter() {
if (window.event.keyCode == 13) {
event.returnValue = false;
event.cancel = true;
}
}
....
</script>
Now, change the body tag to this:
<body onkeydown="stopEnter()">
I like this solution because it universally stops the Enter key without having to add a trap for each textfield on the form. In other words: quick and easy.
Oct 11
richardASP.NET
This is one of those “Sometimes it’s the little things that make a big difference.” I have a feeling that I’ll be posting a lot of these as I transition away from Lotus Notes devlopment to C# and ASP.NET. Easy, simple tips that do exactly what you need when you need it… and, tips that you might not be aware exist.
Here’s my scenario:
I have an ASP form that does not actually get submitted to a database or a workflow. It is a request for the Accounting Department to make a check. We call them Check Requests internally and Accounting will not release the check to you until you produce a printed form with authorized signatures on it. I use ASP.NET to prepare the form and do data validations on it.
So, when the form is “submitted” I make a label visible that says “Don’t forget to print this form and obtain signatures for authorization.” By the way, I need a submit button because it does other things that the user doesn’t care about, so I still need the user to click on a button.
The problem is that when the form is submitted, after the postback, focus is placed at the top of the form. Or, more correctly, focus is not set on any field and the form is simply reposted at the top and my alert label is at the bottom where it cannot be seen.
I could put my warning label at the top[ of the form, but that did not look right to me. If only there was some way to make the position where you had scrolled to "stick" even after the postback. That way, I could keep the label right under the button that the user just clicked.
Hmmm....
Solution: add "MaintainScrollPositionOnPostback="true"" to your <%@page> tag at the top of your ASP form. Like this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NonBillable.aspx.cs" Inherits="CheckRequests.NonBillable" MaintainScrollPositionOnPostback="true"%>
Easy Peasy Lemon Squeezy
[Works with Visual Studio 2008. Not tested with 2003, 2005, or 2010 yet]
Oct 07
richardArt Art
In these difficult economic times what’s better than one of those cheap sketchbooks on the sale rack at Borders or a 50% off coupon on Strathmore sketch pads at Michael’s?
It’s a free sketchbook! Well, almost free if you are a stickler for maintaining that office supply firewall between work-use and personal-use, but that’s between you and your priest.
1. Use up your yellow pad at work during the normal course of business.

2. We use something called the “Ampad evidence Dual-Pad” at work. It has a nice, thick cardboard backing to it. There’s nothing flimsy about this yella-pad. I guess the lawyers like them. I love ‘em!

3. Go visit your office printers. If they are like ours, you will find a stack of discarded printouts next to it. Or, raid the recycle bin.

4. Get a couple of those binder clips. I stole these from Arlene, who sits two cubes down from me.

5. Stack, clip, and start drawing

6. Bask in your low tech bravado as you whip this baby out and begin sketching amongst your friends with their pretentious Moleskines and Strathmore Series 1100 Sheep Vellum Sketchpads. For added panache, use it with an old-school Bic disposable ball point pen with a well-chewed end.
Remember: reuse is better than recycling!
Older Entries