In a recent report from the IBM Center for the Business of Government, government executives are strongly urged not to ignore the use of Web 2.0 technologies in their agencies and to re-think the way they serve the public.
The report is targeted at executive and management-level readers in the U.S. government and provides a nice outline of Web 2.0 technologies, how they are being used, and how the government can and should be leveraging them. Information is conveyed in a non-intimidating but firm manner using terminology and concepts common to the government world.
In my opinion, lacking from the report seems to be a good strategy for self-motivating the government to adopt Web 2.0 practices. The government is not motivated by money in the same manner as businesses and therefore needs a realistic strategy for accepting risk as an acceptable part of innovation.
For much of the government, Evidence-Based Practice (EBP) is substantially the driving force. Unfortunately, acting only on ideas that provide evidence of a sufficient level of effectiveness creates a polarity with innovation. Therefore, what motivation does government have for adopting the always-beta, rapidly changing, and open elements found in Web 2.0?
Government, especially on a national level, typically has measures in place to determine how well it is serving its purpose. Feedback is the profit/loss performance indicator of the government world (at least in the USA). While politics and power-mongering are also forces in the system, as an ordinary citizen, feedback is how we help the government measure its customer service.
The next time you use a government service, don't just accept poor service as being "good enough for government work". If you see improvements in a government service, don't just be surprised and say nothing. In a democracy, the government must hear from the public before it can respond. We are not limited to a little booth on election days to talk to the government. Every government survey, feedback form, comment card, and formal complaint is vote. Don't waste your opportunity to provide the government with the motivation they need to serve the public effectively.
Recently, I had a project where I was wanting to be able to create a reusable UserControl to display tooltips throughout the application. The control would need to access the jQuery framework, a jQuery plugin, required some inline scripting, and had its own class of styles. Not every page in the application would have tooltips but the pages that did use them would have a lot of them.
If I added all the references to the JavaScript and styles in the Master page, I would be introducing unnecessary bloat for the majority of the application. So, I needed a way to request these resources in the UserControl so they would only be added to the page "on demand".
As you might image, adding them directly into the UserControl would mean that the resources would be requested for EVERY instance of the UserControl on the page. If I used the control 10 times, the jQuery framework would get requested 10 times. Not the most efficient design.
Fortunately, the .NET framework has a nice way of dealing with this by providing a way to dynamically add resources AND check to see if they are already loaded.
Dynamically Adding JavaScript
If we just dynamically added links to script files, we would still have the same problem as adding them inline. So, here is a method that checks to see if the script has already been loaded and loads it only if needed:
1: Protected Sub AddScriptFileToPage(ByVal ID As String, ByVal URL As String)
2: If Not Page.ClientScript.IsClientScriptIncludeRegistered(ID) Then
3: Page.ClientScript.RegisterClientScriptInclude(ID, URL)
4: End If
5: End Sub
The one thing to note is that you need to provide some kind of ID for the script. This ID is how .NET checks to see if the script has already been added to the page. Personally, I think that using the filename of the JavaScript helps keep things consistent and kind of makes logical sense but it doesn't really matter as long as it will be unique to that resource.
If you need to add a block of inline JavaScript, no problem. It's basically the same process with a tiny little tweak:
1: Public Sub AddScriptBlockToPage(ByVal ID As String, ByVal Script As String)
2: If Not Page.ClientScript.IsClientScriptBlockRegistered(ID) Then
3: Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), ID, Script, True)
4: End If
5: End Sub
Dynamically Adding Stylesheets
Though not as simple as adding scripts, we can do the same thing for our styles. There are probably a number of way to do this but I chose to check the page header for an existing instance, and add a literal with the link to the stylesheet if it's not found.
1: Public Sub AddCSSFileToPage(ByVal ID As String, ByVal URL As String)
2: If Page.Header.FindControl(ID) Is Nothing Then
3: Dim lit As New Literal()
4: lit.ID = ID
5: lit.Text = "<link rel=""Stylesheet"" type=""text/css"" href=""" & URL & """/>"
6: Page.Header.Controls.Add(lit)
7: End If
8: End Sub
Making it Practical
You might be wondering why you would go through the trouble of doing all this. Lets make this a bit more useful by creating a class to help us use this functionality efficiently. I created a little ResourceLoader class in my application that looked something like this:
1: Namespace Sample
2: Public Class ResourceLoader
3:
4: Public Shared Sub AddScriptFileToPage(ByVal ID As String, ByVal URL As String)
5: Dim p As Page = CType(System.Web.HttpContext.Current.Handler, Page)
6: If Not p.ClientScript.IsClientScriptIncludeRegistered(ID) Then
7: p.ClientScript.RegisterClientScriptInclude(ID, URL)
8: End If
9: End Sub
10:
11: Public Shared Sub AddScriptBlockToPage(ByVal ID As String, ByVal Script As String)
12: Dim p As Page = CType(System.Web.HttpContext.Current.Handler, Page)
13: If Not p.ClientScript.IsClientScriptBlockRegistered(ID) Then
14: p.ClientScript.RegisterClientScriptBlock(p.GetType(), ID, Script, True)
15: End If
16: End Sub
17:
18: Public Shared Sub AddCSSFileToPage(ByVal ID As String, ByVal URL As String)
19: Dim p As Page = CType(System.Web.HttpContext.Current.Handler, Page)
20: Dim lit As New Literal()
21: lit.ID = ID
22: lit.Text = "<link rel=""Stylesheet"" type=""text/css"" href=""" & URL & """/>"
23: If p.Header.FindControl(ID) Is Nothing Then
24: p.Header.Controls.Add(lit)
25: End If
26: End Sub
27:
28: End Class
29: End Namespace
Quick Note: In a class, you can't directly access the Page. So, note how you can declare a Page and then use it in a class environment.
Now that we have this functionality in our application, we can efficiently request resources without having to worry about duplicating what has already been requested for the page. For example, going back to my tooltip UserControl, here is how I could safely make sure that my resources are being requested but not duplicated:
1: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
2: Sample.ResourceLoader.AddScriptFileToPage("jQuery.js", "Script/jQuery.js") 3: Sample.ResourceLoader.AddScriptFileToPage("jQuery.ClueTip.js", "Scripts/jQuery.ClueTip.js") 4: Sample.ResourceLoader.AddScriptBlockToPage("Tooltip.ascx", "$(document).ready(function() {$('a.Tooltip').cluetip({splitTitle: '|'},{cursor: 'pointer'});});)") 5: Sample.ResourceLoader.AddCSSFileToPage("jQuery.ClueTip.css", "CSS/jQuery.ClueTip.css") 6: End Sub
Notice that every instance of the control will make sure that the jQuery framework, the plugin, the inline script, and the custom styles are loaded but, thanks to our handy-dandy ResourceLoader class, no duplication will take place.
Final Thoughts
Even though we aren't duplicating resource requests, we are adding more objects to the page and this potentially introduces latency issues. It also introduces the opportunity to look at how we might extend this technique to combine everything before page makes the request. I've been reading a few ideas on how this might done and, if I end up with a good solution, I'll write a follow up.
If you have any ideas, comments, criticisms, or suggestions please share.
I frequently use the RSSToolkit to consume and display RSS feeds from other blogs. Recently, I've noticed problems with the RSSToolkit not being able to display feed from some external sources. In particular, I've been having trouble consuming feeds from external blogs like Blogspot and Feedburner. The symptoms appeared over the past month or two and included the disappearance of consumed blogs and new blog posts.
After some digging, I found this entry on Obishan's blog that gave me a clue. Using Web-Sniffer, I was able to verify that if no UserAgent was provided for the request, the request was redirected (302). This redirection seems to the source of my problems with the RSSToolkit and I'm not the only one.
This wasn't my first crack at fixing an issue with the RSSToolkit, so I spent some time tracking done how to fix this issue. Basically, I needed to find out where the RSSToolkit was actually requesting the RSS and find out how to modify the request so that it included a UserAgent. In my fix I am hardcoding in the UserAgent. Ideally, this would be set through a property in the control.
The Fix
Step 1: Download the Source
Step 2: Update the Code
Open RSSToolkit > RSS > DownloadManager.cs and replace the DownloadFeedDom() with the following:
private CacheInfo DownLoadFeedDom(string url)
{
//// look for disk cache first
CacheInfo dom = TryLoadFromDisk(url);
if (CacheReadable(dom))
{
return dom;
}
string ttlString = null;
//MODIFICATION: Some RSS sources like Facebook and Feedburner look
//for a UserAgent (browser/OS information)
String userAgent = @"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.UserAgent = userAgent;
HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
XmlDocument doc = new XmlDocument();
doc.Load(httpResponse.GetResponseStream());
httpResponse.Close();
doc.Save(Console.Out);
//END OF MODIFICATION
if (doc.SelectSingleNode("/rss/channel/ttl") != null)
{
ttlString = doc.SelectSingleNode("/rss/channel/ttl").Value;
}
//// compute expiry
int ttlMinutes = GetTtlFromString(ttlString, _defaultTtlMinutes);
DateTime utcExpiry = DateTime.UtcNow.AddMinutes(ttlMinutes);
//// save to disk
return TrySaveToDisk(doc, url, utcExpiry);
}
Step 3: Rebuild the Project and use the new RssToolkit.dll
(Optional) Step 4: Download my copies. My versions also include my fix for Atom feeds.
I bought a discount PC from a highly reputable company (okay, it was Woot) a couple of months ago to replace my aging PC at home. I come from a hardware background so I'm more apt to put up with crappier parts in exchange for a good deal. However, when "crappy" meets "incompatible", I've got problems.
Problem #1:
My new PC came with a dual-head PCIe video card. Cool, I thought. I can just slap my extra PCI video card in the free slot and my 3-monitor setup will just as good as under my older Windows XP machine with the single onboard AGP and added dual-head PCI setup. WRONG! WRONG! WRONG!
Windows Vista is picky about the co-interminglicizing of video cards when using PCI Express. Long story short, don't try it. Either use the same video cards from the same vendor in the same adapter friendly, or prepare for a battle you will lose.
Problem #2
So, it won't work under Vista. Okay, I need 3 monitors more than a pretty-but-bitchy OS (yeah, you know what I mean). I'll just go back to XP on my new machine. NOPE!
Turns out XP doesn't like the chipset in my motherboard and blue screens during setup. Long story short, XP setup does not have the necessary mass storage drivers to get through the setup. Why not load the drivers on a disk and use the F6 method? Well, this system does not have floppy disk support. So, I thought I would be clever and try to slipstream the drivers into a custom XP setup disk. It may have been clever, but it still didn't work.
Bottom Line
I'm pretty much hosed. It's back to my old system that, even though it's not as wizz-diddly as the new one, is still more functional that my new Vista PC that won't run XP.
Moral of the Story
I don't know that there is much to learn here. I guess for a few hundred bucks (cost of the new PC) I learned a lot about about Vista's support for multiple graphics adapters and also how to use slipstreaming to create custom OS setup disks. I also leaned to love the word "slipstream" and plan to use it as often as possible.
Anyone else want a learning experience?
For Sale: One (1) slightly used PC.
Bonus Material
Did you know that "slipstream" can also be defined as "the "burble" of turbulence generated by an object passing through air or space, as the airstream or backwash (wash) around an aircraft from its propulsion?" Awesome! In true tech-style lingo, I give you "BUTT", the newest buzzword for the latest development process designed to intimidate and impress those who are just too stupid to grasp the advantages of having more BUTT action in their environment.
"Burble"-Up Transfer of Technology (BUTT)
The process of slipstreaming lessons learned from past projects into future projects.
A typical web-based authentication system will have two options--Sign In (a path for existing users) and Register (a path for new users). Potential problems for users arise when they don't know if they have an account, or they have tried to sign in unsuccessfully and decide to try to create another account. Typically, when an existing user tries to create another account, they get an error message or some instructions for recovering their information. The user may or may not bother with the effort.
Consider this...How likely is it that an existing user, when trying to create a new account, will use the same or similar information as when they first created their account? Now, imagine if you simply allowed the registration form to also act as a sign in form. Or, make the sign in form step one of the registration process. It should be easy attempt an authentication using the information in a registration form and bypass the actual creation of a new account if an existing account is found, so why not do it?
I know what you're thinking...what if the user *doesn't* enter the same information. For example, what if the username is different but the provided email address matches an existing account. Create a trigger that starts the necessary account recovery process and notify the user what is happening?
By allowing authentication to happen in a registration form you can potentially:
- Unobtrusively sign in existing users who didn't know they had an account.
- Save user frustration by triggering the login recovery process for them using information they already provided.
- Prevent abandonment by users not willing to make the traditional effort.
What do you think? Anyone doing this or considering this approach? Why/why not?
I swear radio buttons pucker up the closer my mouse gets to them. Aside from the lack of good CSS options for radio buttons, they demand a certain level of commitment from the user. Unlike our promiscuous friend the checkbox, once you manage to jab the tip of your mouse into the pinhole of a radio button that's it. There's no unpoking that hole. Sure, you might be able to move it around in a group of radio buttons but, you're pretty much committed to an option.
So, to un-suck the radio button, we need:
- Free will. The users should be able to unselect their answer.
- Mutual exclusiveness. If we don't have this, we've got nothing but checkboxes. Only one answer can be selected.
- Potential beauty: Why be limited to puckered pinholes if we can pretty it up a bit.
By creating a little mash-up using some controls from the AJAX Control Toolkit, maybe we can make something a little better than the standard HTML inputs. Let's be honest. This is not a lightweight approach. I'm not going to tell you what to do but, I would only do this only where the UI bang is worth the page load buck.
Let's tackle mutual exclusiveness first. In case you aren't familiar with the terminology, mutual exclusiveness is the idea that by selecting one item, you exclude yourself from selecting something else. For example, if you chose life, you cannot choose death. To chose death you must not choose life. So, how do we assure a monogamous answer using a bunch of promiscuous checkboxes? For this task, we'll need a chaperone and, fortunately, the Toolkit also has a little thing called a MutuallyExclusiveCheckBoxExtender--just rolls off the tongue doesn't it. This control can make check boxes behave like radio buttons! Yes! No, wait...radio buttons suck, right? A square pinhole is really not that much more fun to poke than a round one, is it?
Enter the ToggleButtonExtender. This AJAX Control Toolkit control allows you override the default HTML checkbox with your own custom images. Sweet! If we use this with some checkboxes, we have achieved "free will" and "potential beauty" in one shot.
By combining a couple of ready-made tools, we can un-suck the radio button by using checkboxes. Hmmm...Maybe I should have titled the article "Checkbox Performance-Enhancing Controls". It doesn't really matter. The goal is to create a better user interface for a task and that's what un-sucking is all about.
Reality Check!
Why NOT to do this:
- The complexity and page size increases exponentially the more options you add so, use wisely.
- You are a Javascript wizard and don't want to add the Toolkit's baggage.
- Getting the selected value for the pseudo-RadioButtonList and validation is trickier. So what? You're a great programmer and can handle it, right?
- It makes it easier for users to see what is selected and not selected. So, if you rely on users not seeing which puckered pinhole they may or may not have selected, don't do this.
Recently, I blogged about my favorite file upload technique for web applications--the free flash/JavaScript-based SWFUpload. While this library is not the perfect solution for all circumstances, it certainly provides a very nice user experience and is worth seeing if it matches your project's requirements.
I have a project I'm working on that needs a graceful file upload process. The environment is compatible with the flash/JavaScript requirements so I made myself a .NET control for the library. The control contains all the necessary JavaScript and you can set the properties (allowed file types, file size, etc.) just like a normal control so you don't have to mess with any of the scripting.
The features of this control include:
- Multiple file upload (queuing)
- Upload progress indicator
- Ability to cancel queued files
- NO visible PostBack (uses AJAX)
For those of you who may be wondering if you just stumbled onto the the "holy grail" of file uploads here, hold y'er horses...
This is my first customer server control ever. I'd never made one before and this was my "learning project". It's probably not a highly tested and production-ready control. That said, you have the source and it's not that complicated so maybe you can customize it or clean it up if necessary. I would like to know what you think--good or bad, so let me know if you find problems or have some ideas to share.
I love multiple monitors. I made everyone at work start using multiple monitors last year. At first they were afraid...they were petrified...but now they don't like working at home if they only have one monitor. If you're looking to justify multiple monitors in your organization, here's a report outlining some productivity research regarding monitor size, aspect ratio, and multiple displays.
Okay, so don't be surprised that display company (NEC) found that larger and more displays improves productivity, but it would appear there is a limit to productivity gains. What's your optimal layout? Check out the report and see for yourself:
On a related note...Here's a gotcha I banged my head into with Vista and multiple monitors...
I recently upgraded my home/office PC. My old system had three monitors under Windows XP and ran great. I used a nVidia AGP card and added an ATI dual-video PCI card to create my surround video.
Enter crotchety ol' Vista with it's fancy-smancy new way of handling multiple graphics cards... Up until now, I've been pretty happy with Vista but this just chaps my hide. If you are planning to use more than two monitors with Vista, you need to read this article first.
It all started with my upgrade to VS 2008. I've been using the trial version and only had 3 days left...time to do the deed.
IMPORTANT SIDE NOTE: If you are using the trial version, you don't need to do a full uninstall/reinstall. I saw this option the very second I clicked the "uninstall" button. That cost me an hour and a half. Live and learn.
Back to the story...at the end of the Visual Studio upgrade I got the option to check for updates which I always do. I am reckless with updates and proud of it. I seem to be addicted to see what's going to happen. Will it work? Will it fail? If it fails, will it be spectacular? OMG, what have I done!...It's so exciting.
For the most part the installation was quite uneventful and I spent most of it daydreaming about my vacation next week.
Then comes the REBOOT! This is the best part of any major update. This is where it can go really really bad, really really fast. I love this part.
System loads. It pauses before the login screen to install the final 3 parts of Service Pack 1. In big bold letters is the warning, "Do not turn your computer off". I'm starting to sweat and my pulse races as it finishes part 1 and moves to part 2 (like I should care what part it's on--but I do!).
Part 2 is almost done then...BAMMMM! It's the final episode of Sopranos!
My screens goes black. The only thing displayed in all three monitors is a cryptic message only a machine could produce.
"!! 0xC00000 !! 255/73694 (_000000000000000.cfg-ms)"
I knew the exclamation points could only mean something tremendous had happened. Clearly, to tremendous to put into words.
I sit there, trembling. I wonder, "Is it dead? Should I leave it and just go home? Should I turn the computer off? No, it said not to. Computers know best, right?"
My hand shook as I held in the power button. Not from fear--from excitement! It's been a long time since I've had this much fun with an update.
I held my breath as it began to restart. My heart was pounding. I'm given a choice "Repair Windows Startup" or "Start Windows Normally".
What's the logical choice? "Repair", you say? As I selected "Start Windows Normally" (honestly, why wouldn't I want it to start anything but "normally"), I sat frozen, hoping it would be okay but at the same time hoping for some kind of explosion.
The update finished normally, and my machine seems none the worse for wear.
Now, isn't there an IE8 Beta out there somewhere...
I recently happened upon this intriguing little API that provides a nice interface for displaying events on a timeline. It was pretty easy to get my head around it and it's pretty easy to setup and use. It's got a Google Maps-like scrolling interface that is very intuitive. If you're not sure what a timeline looks like, you might want to jump straight to an example before continuing.
I've don't really like the standard options for browsing a blogs history which typically looks like this:
- January (10)
- February (5)
- March (11)
- ...
Kind of boring, right? So, as a proof of concept, I created a little test project to see what an RSS feed would look like in a timeline. Here's what it looks like for a busy RSS feed like Techmeme (or, view live demo):
RSS feeds don't typically output an entire history so this example isn't all that practical. However, if I had access to the database I could pull in all the posts to create a full blog timeline. As far as practical applications go, I can think of a number of other scenarios for using an interactive timeline over a plain old list:
- Displaying event logs
- Order tracking
- Live event blogging
- New user registration
- News tickers
- Twitter?
Take a look at the
Simile Timeline page if you would like more information, documentation, or some better examples. You can also download my little
test project/demo.
More Posts
Next page »