10 Replies - 10069 Views - Last Post: 10 March 2010 - 08:50 PM Rate Topic: -----

#1 jfree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-March 10

How to change text in textbox when it is clicked?

Posted 09 March 2010 - 09:01 PM

hi,

i have a username and password textbox. they start off saying username and password in a grey text. what i want to happen is when the user clicks in them the text in them disappears and the user can type in them, however if they are clicked out of before anything is typed the original text reappears. also in the username textbox i want the text that the user types in to be black, and in the password textbox i want the password circles to appear when the user types in their password.

for an example i want them to work exactly like the email and password textboxes on facebook.

im pretty lost on how to do this, not the best at c# yet.

thank you so much for any help on this!!!

Is This A Good Question/Topic? 0
  • +

Replies To: How to change text in textbox when it is clicked?

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: How to change text in textbox when it is clicked?

Posted 09 March 2010 - 09:34 PM

You can use the Enter event of the textbox, then set the Text property of the textbox to string.Empty
Was This Post Helpful? 1
  • +
  • -

#3 jfree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-March 10

Re: How to change text in textbox when it is clicked?

Posted 09 March 2010 - 09:48 PM

the only thing is its an asp.net application, and when i click for the list of events it only has has a few of the events that are there on a windows form application (Enter is not there). instead of clicking on Enter from the list of events, will it work if i just type it in in source code.

sorry if i sound stupid and/or not making sense first time ive messed with an asp.net app, and little programming experience period.
Was This Post Helpful? 0
  • +
  • -

#4 jfree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-March 10

Re: How to change text in textbox when it is clicked?

Posted 09 March 2010 - 09:55 PM

acually yea i just tried what u said in a windows form application and it worked, however it wont work in my asp.net application...any idea why and how i can make it work?

thanks!
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: How to change text in textbox when it is clicked?

Posted 10 March 2010 - 04:32 AM

Use the AJAX TextBoxWatermarkextender.

http://www.asp.net/a...xWatermark.aspx
Was This Post Helpful? 1
  • +
  • -

#6 jfree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-March 10

Re: How to change text in textbox when it is clicked?

Posted 10 March 2010 - 01:51 PM

Thanks alot man! I just have 2 more questions. I want the text in the watermark to be light grey. i saw on the link you gave me, he gave his a colored background, but i think he used a CSS sheet for that. Is there an easier way i can do that in VS? I tried typing in the hexidecimal next to the watermartk text property, but it didnt work. also for my password textbox, how can i make it so dots show up?


Thanks Alot!!!
Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: How to change text in textbox when it is clicked?

Posted 10 March 2010 - 01:59 PM

For the watermarked text color, you will need to use CSS. I don't think it's possible to change that without using CSS. CSS is easy.

After adding a stylesheet to your project, add this to the stylesheet...

.WatermarkTextbox
{
    color: #E8E8E8;
}



Then for the TextBoxWatermarkExtender, you would do this...
<ajaxToolkit:TextBoxWatermarkExtender ID="TBWE2" runat="server"
    TargetControlID="TextBox1"
    WatermarkText="Type First Name Here"
    WatermarkCssClass="WatermarkTextbox" />



Here is a like of grey colors in HEX. Just find the color that you want and replace the HEX in the CSS with the color that you want.

http://www.december....pec/color0.html

For the password, set the TextMode property of the textbox to Password.

This post has been edited by eclipsed4utoo: 10 March 2010 - 02:04 PM

Was This Post Helpful? 1
  • +
  • -

#8 jfree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-March 10

Re: How to change text in textbox when it is clicked?

Posted 10 March 2010 - 02:29 PM

sorry about all the questions lol...last one!!(i think)

when i changed the textmode property to password it also changed my watermark text to dots...any idea how to get around this.

thanks!
Was This Post Helpful? 0
  • +
  • -

#9 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: How to change text in textbox when it is clicked?

Posted 10 March 2010 - 02:51 PM

I don't think it's possible.

This post has been edited by eclipsed4utoo: 10 March 2010 - 02:55 PM

Was This Post Helpful? 1
  • +
  • -

#10 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: How to change text in textbox when it is clicked?

Posted 10 March 2010 - 03:12 PM

I will take that back. I would assume it's possible using Javascript. You can use javascript to determine when the textbox has focus, and then set the textbox's TextMode to password. I only assume this is possible. I have NOT done this myself.
Was This Post Helpful? 1
  • +
  • -

#11 jfree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-March 10

Re: How to change text in textbox when it is clicked?

Posted 10 March 2010 - 08:50 PM

ok. thanks for all the help...man who would have thought there could be so much trouble with a simple textbox! :bananaman:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1