Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Watermark in ASP.NET TextBox using JavaScript

Suggested Videos
Part 3 - JavaScript to select all checkboxes in GridView
Part 4 - Change gridview row color when checkbox is checked
Part 5 - ASP.NET TextBox and JavaScript

In this video we will discuss how to create a watermark in ASP.NET TextBox using JavaScript.

Watermark in ASP.NET TextBox using JavaScript

Here is the HTML and JavaScript used in the video.

Search :
<asp:TextBox ID="TextBox1" ForeColor="Gray"  runat="server" Width="250px"
                Text="Enter your serach term here" 
                onfocus="ClearWaterMark('Enter your serach term here', this);"
                onblur="CreateWaterMark('Enter your serach term here', this);" >
<asp:Button ID="Button1" runat="server" Text="Search" />

<script type="text/javascript">
    function CreateWaterMark(defaultText, textBoxControl)
        if (textBoxControl.value.length == 0)
   = "gray";
            textBoxControl.value = defaultText;

    function ClearWaterMark(defaultText, textBoxControl)
        if (textBoxControl.value == defaultText)
   = "black";
            textBoxControl.value = "";

JavaScript with ASP.NET tutorial

1 comment:

  1. Hi Sir, thank you very much from your training videos, i want to implement the WaterMark using visual studion 2010 language. but it give me the error in compilation, the error couldnt recognize onfouce and onblur event.


It would be great if you can help share these free resources