ASP.NET Custom Server Controls: WordHack Control
(Page 1 of 5 )
This article introduces you to creating a “WordHack” control, which can hack the words you type within a browser environment and automatically redirect to a website based on the user specified hacking word.
A downloadable file for this article is available
here.
The sample downloadable solution (zip) is entirely developed using Visual Studio.NET 2003 Enterprise Architect on Windows Server 2003 Standard Edition. But, I am confident that it would work with other versions of Windows (which support .NET 1.1) as well.
What is this “WordHack” all about?
This is the main question everyone would ask. Before the evolution of the mouse device, everyone liked to type through the keyboard (as it is much smoother than an ordinary typewriter). When the mouse arrived, everyone wanted to work with the mouse (as it is very easy and flexible to work with a GUI). Non-typists (who don’t know any fundamentals of typing) use the mouse, as if it is a point of survival for them. They become very furious if they can't find the mouse, or if the mouse does not work.
Then came "hot keys” (or shortcut keys). I don’t think there exists anybody in this world who does not know about the “Ctrl+C” and “Ctrl+V” key shortcuts. They are famous, even in the post-mouse era. Day by day plenty of shortcut keys are being introduced (or even added) to several applications. Finally, what about the web?
Even a web page has its own way of capturing the shortcut keys using JavaScript code. If you are working with Yahoo!Mail or Gmail, plenty of shortcuts already exist to help you do things faster. Now, why don’t we design our own custom control (in ASP.NET), which can be used to capture the keys the user is typing within a web page? Why not!
This article covers that very topic. I don’t want to introduce very sophisticated methods of capturing keystrokes at the very beginning. We shall increase the sophistication (or complexity) bit by bit within this series of articles. Initially, I start with designing a simple custom control, which captures a particular word typed by the user and automatically redirects to a particular page upon typing it. It would work regardless of any control.
So, for example, if I type “yahoo” blindly on a web page (either in a text box or even on a page without a control), it has to automatically redirect to www.yahoo.com. You may be wondering why we need this! But, you will be astonished to know that one of our clients asked us to implement the acceptance of keyboard based “logout” (regardless of any web page or any control they type) to immediately log out their intranet website. They just wanted to hack the word “logout” (when the user types it) and immediately proceed to the “log out” operation.
At the beginning, I was almost shocked when they told me their requirement. They claimed that it was a simple one! I started crying in my mind about their craziness. We somehow implemented it using JavaScript. They were delighted. Later they explained, almost reasonably, that “typing LOGOUT from keyboard” is much faster than “finding and clicking on logout.” And, of course, later they asked us to implement several other keyboard based “WordHacks.”
I request every reader to consider my apologies in explaining such a big story (without any technical content on this page). But, I hope you have already understood the concept, on which I contributed this article.
So, let us start getting into the details of the “WordHack” control.
Next: What are the properties declared and how do we work with the control? >>
More ASP.NET Articles
More By Jagadish Chaterjee