In this post, we will learn how to add a watermark inside a textbox using AJAX Control Toolkit in C#. For this example, first, we have to install the AJAX Control Toolkit from NuGet packages. For this example, we have to add a ScriptManager, an ASPX TextBox, and aTextBoxWatermarkExtender for displaying the watermark text in the textbox. Let's start coding.
Install the AJAX Control Toolkit from NuGet Package Manager. Right click on the project and click on "Manage NuGet Packages". Type Ajax Toolkit and install.


When clicking on "Choose items", the below dialog is opened.

After opening the above dialog, click on the browse button and go to your project's bin folder for adding this AJAX Control Toolkit dll.

All the above steps are completed, now, we can use the AJAX Control Toolkit controls in our toolbox. First, we have to add a ScriptManager from AJAX Extension inside the form tag.
Now, write the below code for displaying a water mark in the textbox.
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TextBoxWaterMarkForm.aspx.cs" Inherits="TextBoxWaterMarkForm" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>TextBoxWatermarkExtender</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
- <div>
- <asp:TextBox runat="server" ID="TextBox1"></asp:TextBox>
- <ajaxToolkit:TextBoxWatermarkExtender ID="TBWE2" runat="server"
- TargetControlID="TextBox1"
- WatermarkText="Type First Name Here"
- WatermarkCssClass="watermarked" />
- </div>
- </form>
- </body>
- </html>
Before Click

After Click


Join the conversation! Your thoughts help the community grow.