Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

AJAX Text Box Watermark Extender

Viewed:  2492 
Posted On:  19/07/2012 22:05:05 
This article shows how to use two new AJAX Controls, TextBoxWatermarkExtender and ValidatorCalloutExtender in ASP.NET 3.5. 

In this article, I am going to show two AJAX Control - TextBoxWatermarkExtender and ValidatorCalloutExtender. We use error validation control, now by using AJAX we can use these controls in a very attractive way.

Here are the brief descriptions of these two controls.


This Ajax control attached to Textbox control to get WaterMark behavior. When a Textbox control is empty it display Watermark text.To attach TextBoxWatermarkExtender to TextBox, set TargetControlId of TextBoxWatermarkExtender to particular TextBox. Here, I set TargetControlID of twFirstname to txtFirstname and set WatermarkText for txtFirstname.


This Ajax control enhances the functionality of existing ASP.NET validators. To use this control, add an input field and a validator control as you normally would. Then add the ValidatorCallout and set its TargetControlID property to reference the validator control.

The following code of ASP.NET page shows how to use both of these controls.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""">

<html xmlns="">
<head runat="server">
    <title>AJAX :: TextBoxWatermarkExtender</title>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <table cellpadding="0" cellspacing="0" width="50%" align="center">
                            <table cellspacing="3" width="50%" align="center" style="margin: 0px 5px 0px 5px;">

                                    <td align="center" style="font-weight: bold;">
                                        <asp:TextBox ID="txtFirstname" runat="server" />
                                        <asp:RequiredFieldValidator ID="rfvFirstname" runat="server"ErrorMessage="Enter Your First Name"

                                            ControlToValidate="txtFirstname" Display="None"ValidationGroup="vgCheck" />

                                        <ajaxToolkit:TextBoxWatermarkExtender ID="twFname"runat="server" TargetControlID="txtFirstname"

                                            WatermarkText="Enter Your First Name" />

                                        <ajaxToolkit:ValidatorCalloutExtender ID="vcFname" runat="server"TargetControlID="rfvFirstname" />

                                        <br />
                                        <asp:Button ID="btnSubmit" runat="server" Text="Submit"ValidationGroup="vgCheck" />


When I run the application, you will see output like following:


If I click on Submit button without entering name in text box then error message will show in a attractive way. We can design this more by using CSS class.


         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us