Click here to Skip to main content
12,070,171 members (28,004 online)
Rate this:
 
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.8K
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 25-Feb-13 9:17am
   
My 5.
Orcun Iyigun 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 26-Feb-13 2:59am
   
i am using visual studio 2008 it is not working sir..
Nandakishorerao 26-Feb-13 3:36am
   
how did you add...paste it
ntitish 26-Feb-13 4:32am
   
first i pasted sir after words i tried by typing but it is not coming
Nandakishorerao 26-Feb-13 6:13am
   
which is the browser you are using?
ntitish 26-Feb-13 7:06am
   
internet explorer while testing through local host
Nandakishorerao 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 27-Feb-13 0:17am
   
there is no solution for this sir...
Nandakishorerao 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 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 28-Feb-13 5:12am
   
this i can write on content page ha sir.....
Asim Mahmood 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160208.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2016
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