CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Brendan Tompkins [MVP]

Blog First. Ask Questions Later.

How To: Make a Web Smart Tag

Last year I created a SmartTag for Office XP for internal use here at the Port.  It's been a success, and recently our director asked if I could do something similar for our Web Site.  Specifically, he wanted a popup context menu to appear whenever there was a container number on the site.  This menu would allow the user to perform specific tasks for that container. Luckily our container number follows a standard format (4 characters, followed by 6 or 7 Numbers) which makes picking them out of a stream with regex a fairly simple task. I was able to create a role-specific context menu for all container nubmers on our site.  Since we have a bunch of applications and reports that present container nubmers,  this Web Smart Tag instantly enbaled application functionality to all of these pages.  This is pretty powerful stuff, and we didn't have to touch each individual page's code to enable this.

The end result works pretty well, so I thought I'd show how I did it here. My solution uses a technique for applying a filter to the outgoing http stream, as described here by Donny Mack.  It also uses the excellent MarkItUp Context Menu, by Darren Neimke (I'll post a link when to the download when I can find it again).

First of all, if you're going to be creating a SmartTag, you're going to need something that follows a pattern that you can regex.  For example, social security #'s, phone #'s, email addresses are good candidates for a SmartTag, Surnames are not.

So say you have your text that you are going to create your smart tag from, here's one way to create the tag.  This example uses ISBN #s and provides a context menu to allow lookup at Amazon or Barnes & Noble. You can download a web project here that demonstrates the technique in full.  Here's what the result looks like:

A couple of caveats.  A real smart tag will have to account for all sorts of cases where the pattern is found and you don't want to create a tag.  For example, when your pattern occurs  inside a hyperlink. Be prepared to do some serious regex back referencing.  I'd suggest grabbing a copy of Roy's Regulator which is a fantastic tool for editing and testing regex.  Another gotcha is that this can slow down the processing of your site.  I actually had to do a number of performance enhancements before I could release the production code (like compiling the regex into an assembly, and only filtering certain pages) but generally this approach here works.

-Brendan



Comments

Brendan Tompkins said:

Thanks Joseph! Let me know if it works out for you.
# August 25, 2004 2:53 AM

Anu said:

Not able to download the code.. please check it

# October 15, 2007 7:59 AM

Anuja said:

Link to download the web project is not working

# October 16, 2007 1:46 AM

Brendan Tompkins said:

Anu,

Thanks, try now.

# October 16, 2007 9:15 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Brendan Tompkins

Brendan has been programming with .NET since the first public beta and is owner and operator of Port Technology Services, a consultancy company providing .NET application development services to the Maritime industry. In July, 2007, he was awarded the Microsoft MVP award for ASP.NET. He's also a proud co-founder of failed .COM startup Intrinsigo, and has had a hand in the failure of numerous other businesses. He currently runs CodeBetter.Com and Devlicio.us, and lives in Norfolk, Virgina with his wife Tiara and son Ian.

View Brendan's profile on LinkedIn

Check out Devlicio.us!

Our Sponsors