Skip to main content
Email Password   helpLost your password?

Update History

Wednesday August 30, 2006: Patched the Single Quote bug. The library used to brake down when a single quote was supplied in WatermarkText

Wednesday August 23, 2006: Patched the library to work with FireFox. 

Introduction

You may have seen some web sites displaying watermarks in text boxes. As soon as you click on a text box, the watermark disappears and you can start entering text. In this article, I will explain a small JavaScript trick that you can use to do the same in your web application. I have included a library that you can use to achieve the same functionality without having to worry about JavaScript. 

Sample screenshot

Background

The idea is to capitalize on OnFocus and OnBlur events of the HTML input tag. The library sets flips between two styles for the input tag and, also, it checks if the default text has been changed or not.

Using the code

To use the code, you need to provide at least two styles for the text box. First that represents the watermarked textbox and another that represents a normal textbox. The sample project includes such a stylesheet.

To apply watermark to a textbox with id=textbox1, write the following in your page_load event handler. 

TextBoxWatermark.WaterMarkHelper.ApplyWaterMarkToTextBox(
                        textBox1, "Watermarktext", "WaterMarkedTextBoxStyle", "NormalTextBoxStyle")

Enhancements

You can enhance the library to intercept the submit event and remove the default text before required field validators fire.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralPassword boxes Pin
Johnny J.
0:53 10 Mar '09  
QuestionMissing Library in Source Zip Pin
Dapo Onawole
1:07 19 Nov '08  
AnswerRe: Missing Library in Source Zip Pin
Deobrat Singh
1:17 19 Nov '08  
GeneralRe: Missing Library in Source Zip Pin
Dapo Onawole
2:22 19 Nov '08  
GeneralRe: Missing Library in Source Zip Pin
Deobrat Singh
2:24 19 Nov '08  
GeneralC# Version Pin
BronwenZande
16:42 2 Jan '07  
GeneralASP.NET 2.0 ISSUE Pin
RogerMCT
8:34 23 Oct '06  
AnswerRe: ASP.NET 2.0 ISSUE Pin
Deobrat Singh
19:01 23 Oct '06  
GeneralHow to customize the messages while setup the application using vb.net? Pin
xxxxxxxxxchandra
1:43 30 Aug '06  
QuestionWatermark library and single quotes Pin
pbishop
10:10 29 Aug '06  
AnswerRe: Watermark library and single quotes [modified] Pin
Deobrat Singh
10:29 29 Aug '06  
GeneralRe: Watermark library and single quotes Pin
pbishop
10:49 29 Aug '06  
GeneralRe: Watermark library and single quotes [modified] Pin
Deobrat Singh
11:06 29 Aug '06  
GeneralRe: Watermark library and single quotes [modified] Pin
Deobrat Singh
20:47 29 Aug '06  
GeneralRe: Watermark library and single quotes Pin
pbishop
4:30 30 Aug '06  
GeneralAtlas can do this too with control extenders Pin
Robert Ensor
21:12 22 Aug '06  
GeneralRe: Atlas can do this too with control extenders [modified] Pin
Deobrat Singh
21:46 22 Aug '06  
GeneralValidators? Pin
rjpaulsen
10:20 22 Aug '06  
GeneralRe: Validators? Pin
Deobrat Singh
19:29 22 Aug '06  
GeneralRe: Validators? Pin
itsmaryann
1:04 8 Sep '08  
GeneralFireFox Problem Pin
asifrazach
5:19 22 Aug '06  
GeneralRe: FireFox Problem [modified] Pin
Deobrat Singh
19:31 22 Aug '06  
GeneralRe: FireFox Problem [modified] Pin
Deobrat Singh
23:34 22 Aug '06  
GeneralRe: FireFox Problem Pin
asifrazach
3:08 23 Aug '06  
GeneralCSS Pin
ANameNotRegistered
1:27 16 Aug '06  


Last Updated 29 Aug 2006 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009