Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
i want to show the default value in the textbox1 in lite color before entering any value into the same text box
 
//example
when we are using any social networking sites means we will face this type of one while entering any name in the textbox..before only we will see name in lite color...when the courser goes into that textbox..automatically it will disappear
Posted 25-Feb-13 2:15am
ntitish1.6K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You should look into Ajax Control Toolkit's TextBox Watermark .
 
For more info:
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/TextBoxWatermark/TextBoxWatermark.aspx[^]
 
Good luck,
OI
  Permalink  
Comments
Marcus Kramer at 25-Feb-13 9:17am
   
My 5.
Orcun Iyigun at 25-Feb-13 10:16am
   
Thank you Marcus.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use Placeholder attribute inside the textbox.
 
example-
<asp:TextBox ID="txtName" PlaceHolder="Enter Your Name" runat="server"></asp:TextBox>
 
it works.
  Permalink  
v2
Comments
ntitish at 26-Feb-13 2:59am
   
i am using visual studio 2008 it is not working sir..
Nandakishorerao at 26-Feb-13 3:36am
   
how did you add...paste it
ntitish at 26-Feb-13 4:32am
   
first i pasted sir after words i tried by typing but it is not coming
Nandakishorerao at 26-Feb-13 6:13am
   
which is the browser you are using?
ntitish at 26-Feb-13 7:06am
   
internet explorer while testing through local host
Nandakishorerao at 26-Feb-13 7:37am
   
oh..then it will not work in IE since it is html5 attribute..check with other browsers it works.
ntitish at 27-Feb-13 0:17am
   
there is no solution for this sir...
Nandakishorerao at 27-Feb-13 1:44am
   
there is solution....but there are some third party lib which can be used..but use the javascript as mentioned in solution 3...or
add this in textbox and try
onfocus="if(this.value=='Enter Your Name'){this.value='';}"
onblur="if(this.value==''){this.value='Enter Your Name';}"
ntitish at 27-Feb-13 4:40am
   
thanks sir....
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Follow this code you'll achieve your goal.
 
function onFocus() {
            var txtBox = document.getElementById('<%=TextBox1.ClientID %>');
            if (txtBox.value == "User Name") {
                txtBox.value = "";
                txtBox.style.backgroundColor = "white";
                txtBox.style.color = "Black"
            }
        }
        function onFoucsOut() {
            var txtBox = document.getElementById('<%=TextBox1.ClientID %>');
            if (txtBox.value == "") {
                txtBox.value = "User Name";
                txtBox.style.backgroundColor = "Azure";
                txtBox.style.color = "Silver";
            }
        }
 

<blockquote class="FQ"><div class="FQA">Quote:</div> ></blockquote>
  Permalink  
v2
Comments
ntitish at 28-Feb-13 5:12am
   
this i can write on content page ha sir.....
Asim Mahmood at 28-Feb-13 5:28am
   
any where sir but you write Js code in js file.

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

  Print Answers RSS
0 /\jmot 210
1 Richard Deeming 195
2 Richard MacCutchan 190
3 Zoltán Zörgő 175
4 Peter Leow 170
0 Sergey Alexandrovich Kryukov 9,353
1 OriginalGriff 6,881
2 Peter Leow 4,537
3 Zoltán Zörgő 4,009
4 Richard MacCutchan 2,882


Advertise | Privacy | Mobile
Web02 | 2.8.150129.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100