Step 1
In this blog, we will show you how can you display a watermark in ASP.NET of a textbox, using JavaScript.
Step 2
Prior to it, we need to create a new ASP.NET application and add a textbox control on the page. For this, create a new ASP.NET code, which is given below.
- <div>
- Username :<asp:textbox ID="txtUserName" Text="Use ; as a separator" Font-Bold="true" onfocus="WaterMarkFocus(this,'Enter the username')" onblur="WaterMarkBlur(this,'Enter the username')" runat="server" ForeColor="gray" ></asp:textbox>
- </div>
- <script type="text/javascript">
- function WaterMarkFocus(txt, text) {
- if (txt.value == text) {
- txt.value = "";
- txt.style.color = "black";
- }
- }
- function WaterMarkBlur(txt, text) {
- if (txt.value == "") {
- txt.value = text;
- txt.style.color = "gray";
- }
- }
- </script>
Step 5
When a user will focus on a textbox, the watermark text will disappear and on removing the mouse, the water mark text will appear. In some cases, until the user types, it will remain the same.


Nigel FernandesPosted Jan 19, 2017, 11:55 PM
HTML attribute placeholder does that ... http://www.w3schools.com/TAgs/att_input_placeholder.asp