4

I want to use a textbox that shows a text.

For example : Someone@example.com. When the user clicks on it, the textbox is cleared and ready for the user to type.

sample textbox

slfan
  • 8,950
  • 115
  • 65
  • 78
Mojtaba
  • 51
  • 1
  • 2
  • 7

6 Answers6

6

If you are working on newer browsers then you can use placeholder property which is new in HTML 5

<asp:TextBox ID="textBox1" runat="server" placeholder="Someone@exmaple.com"></asp:TextBox>

otherwise you can also use onfocus and onblur event to do this as described here

Community
  • 1
  • 1
Sachin
  • 40,216
  • 7
  • 90
  • 102
2

you can use this, is so easy

 <input class="status" type="text" size="5" placeholder="started"  />

placeholder show you the text you want

hope it helps you!

Alsan
  • 325
  • 1
  • 5
  • 12
0

You can do the following:

  1. Add textbox to your webpage.
  2. Set the default text in the obj.Text property.
  3. Add properties ( focus & blur events).
  4. On focus event, check if the value = Someone@exmaple.com , then empty the text box.
  5. On blur, check if the textbox is empty, then set the text : Someone@exmaple.com

Hope that helps

शेखर
  • 17,412
  • 13
  • 61
  • 117
0

You can use like this

<TextBox ID="txtone" runat="server" tooltip="Enter comments"
onblur="if(this.value=='') this.value='Someone@exmaple.com';"
onfocus="if(this.value == 'Someone@exmaple.com') this.value='';"
Text="Someone@exmaple.com"></TextBox>
शेखर
  • 17,412
  • 13
  • 61
  • 117
0

Try this for a server control:

<asp:TextBox ID="textBox1" runat="server" placeholder="Someone@exmaple.com"></asp:TextBox>

For an HTML control:

<input Type="Text" ID="textBox1"  placeholder="Someone@exmaple.com" />
legoscia
  • 39,593
  • 22
  • 116
  • 167
Sagar Hirapara
  • 1,677
  • 13
  • 24
0

You can use this ajax if you want a cross browser compatible version.

<ajaxToolkit:TextBoxWatermarkExtender ID="EmailClear" runat="server" TargetControlID="EmailAddress" WatermarkText="Someone@example.com" />

You just have to add this under each field.

huddds
  • 1,045
  • 6
  • 27
  • 47