ASP.NET - textbox problem - Asked By Pratik Kantharia on 07-Apr-10 05:19 AM

i have 3 text box. 

txtfname,  txtmaname, txtlname .

i want to do like this 

txtfname hava text first name. when i click on txtbox it has been blank.
 plz dive answer with solution.
Anoop S replied to Pratik Kantharia on 07-Apr-10 05:26 AM
you can write code GotFocus Event of the textbox
txtfname.Text=""
Santhosh N replied to Pratik Kantharia on 07-Apr-10 06:00 AM
You could do that using simple javascript in onfocus event...

<asp:TextBox Id=txtFName runat=server onfocus="ClearValue(this);" Text="First Name" onblur="ResetControl(this, 'First Name');"></asp:TextBox>

and in script

function clearControl(cntrl)
{
cntrl.Value = "";
}

function ResetControl(cntrl, message)
{
if(cntrl.Value == '')
{
cntrl.Value = message;
}
}

Rahul Kumar replied to Pratik Kantharia on 07-Apr-10 06:53 AM

Check this code, I think it'll fullfill your need

<asp:TextBox ID="TextBox1" runat="server" Text="First Name" onFocus="javascript:this.value=(this.value=='First Name' || this.value=='' ?'':this.value)" onBlur="javascript:this.value=(this.value=='First Name' || this.value=='' ?'First Name':this.value)"></asp:TextBox>