Tuesday, 22 July 2014

Display Watermark Text in a Password TextBox Using jQuery In Asp.Net

7/22/2014 - By Pranav Singh 2

This article I will show you how you how you can display the watermark in a password textbox using jQuery in asp.net. So for this article we will learn to display watermark in a password textbox using jQuery in asp.net. This article will cover following topics simple way to provide watermark Text to ASP.NET Textbox, Display watermark text when textbox Textmode=Password.


So first we will download some jquery library for completing this article.


So for this article first we will create an asp.net application and add the above jQuery library reference after downloading in out project.

So after completing all above activity we will use the below code to display the water mark in a textbox of asp.net using jQuery.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WaterMark_TextBox_Asp.net.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery.watermark.min.js" type="text/javascript"></script>
    <title>Display Watermark Text in a Password TextBox Using jQuery In Asp.Net</title>
    <script language="javascript">
        $(function () {
            $("#txtusername").watermark("Enter your username");
            $("#txtpassword").watermark("Enter your password");
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <fieldset>
            <legend>Watermark in a password TextBox</legend>
            <ol>
                <table width="100%" cellspacing="3" cellpadding="3">
                    <tr>
                        <td align="right">
                            Username :
                        </td>
                        <td align="left">
                            <asp:TextBox ID="txtusername" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            Password :
                        </td>
                        <td align="left">
                            <asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </ol>
        </fieldset>
    </div>
    </form>
</body>
</html>

Please check the below jQuery code to display the water mark

    <script language="javascript">
        $(function () {
            $("#txtusername").watermark("Enter your username");
            $("#txtpassword").watermark("Enter your password");
        });
    </script>

Now run the application to check the functionality.


DOWNLOAD

Tags: ,
About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

2 comments:

  1. This code fails because ASP.NET does render txtusername with the same name. Please don't post code if it doesn't remotely work.

    ReplyDelete
  2. very good example and easy to understand.

    ReplyDelete

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top