Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD

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:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" />

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

    function ClearWaterMark(defaultText, textBoxControl)
    {
        if (textBoxControl.value == defaultText)
        {
            textBoxControl.style.color = "black";
            textBoxControl.value = "";
        }
    }
</script>

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 vb.net language. but it give me the error in compilation, the error couldnt recognize onfouce and onblur event.

    ReplyDelete

If you like this website, please share with your friends on facebook and Google+ and recommend us on google using the g+1 button on the top right hand corner.