The Microsoft Ajax Control Toolkit (ACT) contains a TextBox Watermark control.
I’ve started to write samples to implement all the ACT features with jQuery (and jQuery plugins), you can read more HERE.
Here is the effect we’re looking for, a hint to the user as to the desired or required input (note this sampe doesn’t do input validation, we’ll do that in a later demo.)
The effect is completely applied in our markup. There is no server side implementation.
I like this as I prefer to off load as much work as possible to the client machine.
Note that in the “HeadContent” placeholder I pull in jQuery and the TinyWatermark jQuery Plugin. (I’m using the VSDOC version for the best experience in Visual Studio but you should use the MIN version in production, and consider using the Microsoft CDN
Starting on line 7 I specify a style to be used for the watermark (and names .watermark)
Any texbox that I want to be watermarked I set it’s class=watermark
Note also that the jQuery plugin will use the title attribute as the text to displain in the textbox when the watermark is active as set on line 31.
Then all we have to do is simple apply the JavaScrpt function that begins on line 16.
You can download a runnable sample [ HERE ]