Click here to Skip to main content
16,007,885 members
Articles / Web Development / ASP.NET
Article

Creating a watermark ("") textbox control

Rate me:
Please Sign up or sign in to vote.
3.09/5 (12 votes)
23 Mar 2006CPOL 49.3K   407   43   2
This article describes the implementation of a watermark textbox control.

Sample Image - WatermarkTextBoxControl.jpg

Introduction

This article shows the source code required to create a textbox control which will show a default string when no content is entered. This can be a useful feature when you need to guide a user in filling in the required data in a web form.

Typical uses of this control include showing "< enter your text here >" or "< search terms >" in gray in a search box in a web page.

The control shows the text when no content is entered, and removes the text when the control receives focus (when the textbox is selected by mouse or by pressing tab, in the onFocus event). When the control loses focus (in the onBlur event), when no text is entered, the watermark text is again inserted in the textbox.

Usage

Typical usage of this control is demonstrated here:

ASP.NET
<%@ Register TagPrefix="WeSeeSc" 
  Namespace="We.See.Web.ServerControls" Assembly="ServerControls" %>

Search:
<WeSeeSc:WatermarkTextBox id="query" Runat="server" 
  Watermark="< enter your question >"></WeSeeSc:WatermarkTextBox></TD>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Netherlands Netherlands
PuReBRaiNZ has been programming in all microsoft supported languages for nearly ten years. His current job is in ms (asp.net & sql) consultancy in the Netherlands.

Comments and Discussions

 
QuestionPassword mode not supported Pin
rlaemmler29-May-07 4:27
rlaemmler29-May-07 4:27 
Hi Steve,

Thanks for posting this. I try to use your WatermarkTextBox but it seems not to support if the textbox is in Password mode. I'm not sure whether this is even possible!?


Reto Laemmler
www.xcellery.com
GeneralNice Idea Pin
Steve Maier24-Mar-06 4:18
professionalSteve Maier24-Mar-06 4:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.