Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Creating a watermark () textbox control

0.00/5 (No votes)
24 Mar 2006 1  
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:

<%@ 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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here