Click here to Skip to main content
15,883,853 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi frnds!!!!
how do taking a label in the middle of text box. For example in Facebook when we sign up and we enter our name email and password.

UPDATE

When we make account In Facebook they want information we enter our first name, last name email password etc. when we click on last name, first name text box and last name written in text box disappear and we write our name in text box.
Posted
Updated 17-Mar-14 2:54am
v2
Comments
nandakishoreroyal 17-Mar-14 7:31am    
I think it happens in chrome, auto filling option..
Sampath Lokuge 17-Mar-14 7:33am    
Your question is incomplete.So provide more info.
Aisha Ali khan 17-Mar-14 8:00am    
ok When we make account In Facebook they want information we enter our first name, last name email password etc. when we click on last name, first name text box and last name written in text box disappear and we write our name in text box.
BillWoodruff 17-Mar-14 8:03am    
Is this an ASP.NET application ? Please tag your question.
Aisha Ali khan 17-Mar-14 9:43am    
sir my question is in c#

In ASP.NET MVC the code for doing this is by using java-script in razor view like in the next example:

@Html.TextBox("searchValue", Session["SearchValue"] == null || ((string)Session["SearchValue"]).Length == 0 ? Resources.Resource.SearchLabel : (string)Session["SearchValue"], new { @class = "quickSearchTextBox", onFocus = "if (this.value=='" + Resources.Resource.SearchLabel + "') this.value='';"})



The idea is to test if the user input something (or delete all) in the text box, and in the case there is no input to show a message hint, otherwise to keep the user input. In the code above I keep in the Session the value input by user to not lost it between post backs.
 
Share this answer
 
Comments
Aisha Ali khan 17-Mar-14 9:44am    
ok thanks!!!!!
Sampath Lokuge 17-Mar-14 9:51am    
If this is the answer.Please accept it.
Aisha Ali khan 17-Mar-14 9:55am    
ok!
Volynsky Alex 17-Mar-14 17:09pm    
Yes this is a good answer!
That is called, placeholder.
I'm taking a ASP .NET example to explain you this.
ASP
<asp:textbox id="fnameTxt" runat="server" placeholder="First Name" />

Or may find bit more appropriate answer on W3c[^].

Good Luck :)
-KR
 
Share this answer
 
v2
Comments
Aisha Ali khan 17-Mar-14 10:30am    
ok Thanks
Krunal Rohit 17-Mar-14 10:45am    
Glad I could help :))

-KR

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900