python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
Create Watermark TextBox using JavaScript in ASP .Net.

Create Watermark TextBox using JavaScript in ASP .Net.

Hi everyone,

In this post, i'm going to share to code snippet for create watermark in a asp.net textbox using JavaScript.

This example is simple and understandable code-sample using JavaScript and asp.net c#


Table of Contents

1. In the 1st step, code-sample for aspx page.
2. In the 2nd step, code-sample for C# (.cs page).
3. In the 3rd step, code-sample for JavaScript.

In the 1st step, code-sample for view in asp.net page i.e. .aspx



<asp:TextBox ID="txtURL" runat="server" Width="300px" Text = "http://aspdotnetblogspot.blogspot.in/"  onblur = "WaterMarktext(this, event);" onfocus = "WaterMarktext(this, event);"> </asp:TextBox>


In the 2nd step, code-sample for c# .net page i.e. .aspx.cs

if (!Page.IsPostBack)
{
    txtURL.Attributes.Add("onblur", "WaterMarktext(this, event);");
    txtURL.Attributes.Add("onfocus", "WaterMarktext(this, event);");
}

In the 3rd step, code-sample for JavaScript page i.e. .aspx page


<script type = "text/javascript">
    var varText = "http://aspdotnetblogspot.blogspot.in/";
    function WaterMarktext(txt, evt) {

        if (txt.value.length == 0 && evt.type == "blur") {
            txt.style.color = "green";
            txt.value = varText;
        }

        if (txt.value == defaultText && evt.type == "focus") {
            txt.style.color = "green";
            txt.value = "";
        }
    }
</script> 
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions