Default empty text in a textbox

  • Thread starter Nuyttens Xavier
  • Start date
N

Nuyttens Xavier

Hi,

I'm new to writing web user controls, but I would like to write my own
textbox usercontrol (asp.net 2.0 / c#) that has this feature :
- When the textbox is empty, the .text value is set to a default textvalue
like "type your message here"
- When you click the textbox, the .text is reset to blank
- When you query the .text value it returns the actual value, so it should
be empty if the user didn't type anything (not the default empty text).

Can anybody help me with a good way to implement this feature ?

thanks alot!

Xavier
 
T

TiSch

Hi,

I'm new to writing web user controls, but I would like to write my own
textbox usercontrol (asp.net 2.0 / c#) that has this feature :
- When the textbox is empty, the .text value is set to a default textvalue
like "type your message here"
- When you click the textbox, the .text is reset to blank
- When you query the .text value it returns the actual value, so it should
be empty if the user didn't type anything (not the default empty text).

Can anybody help me with a good way to implement this feature ?

thanks alot!

Xavier

Hello,

you need JavaScript for this:

<asp:TextBox ID="DefaultTextBox" Runat=server onfocus="this.value=''"
onblur="if(this.value.length==0)this.value='enter text here'">enter
text here</asp:TextBox>

in the Codebehind you have only to check if the textbox value is the
default text or not. Then save String.Empty or the actual value.

regards,
Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top