Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Changing the color of the text box when i am entering the details.and after that it should go to the previous color.
that means i want display the text box in two colors when i am entering the details and when i am not entering the details..
Posted
Comments
Rahul K Singh 17-Dec-12 5:47am    
I guess you need some kind of CSS which will do all this.
Zaf Khan 18-Dec-12 22:59pm    
The sample i provided is in CSS and can work with ANY number of controls, wether textboxes or panels butons or any other HTML element that can accept style.backgroundcolor property (which is practically 99% of them)

Try following

XML
<asp:TextBox ID="txtURL" runat="server" Text="&hello" TextMode="MultiLine" MaxLength="200" onFocus="this.style.background ='yellow'" onblur="this.style.background='white'"></asp:TextBox>



Thanks
 
Share this answer
 
Whatever styling name you have used to STYLE your text boxes...
You just duplicate the style then add :Hover to its name and modify the style

Lets say its called MyTextStyle

Then in your stylsheet it may appear as below...

The style below gives you white background and red text
CSS
.MyTextStyle
{
  Color: #FF0000;
  Background-color: #FFFFFF;
}



The style below gives you Black background and white text
CSS
.MyTextStyle:Hover
{
  Color: #FFFFFF;
  Background-color: #0000;
}


This is probably the BEST way to do it
 
Share this answer
 
Write this under TextChanged Event..
C#
if(TextBox1.Text == string.Empty)
{
   TextBox1.Backcolor = Color.Red;
}
else
{
   TextBox1.Backcolor = Color.Green;
   TextBox1.Forecolor = Color.White;
}
 
Share this answer
 
Comments
ntitish 17-Dec-12 5:36am    
Sir i had so many text boxes in my registration and in web site.......cant we change in designing part.
[no name] 17-Dec-12 5:38am    
not getting you clearly...
ntitish 17-Dec-12 5:51am    
its ok sir i got my answer.thanks
[no name] 17-Dec-12 6:01am    
If you're satisfied with the given answer, Accept the Solution :)
-Krunal R.
XML
<script type ="text/javascript">



    function ChangeBorder(obj, evt)

    {

        if(evt.type=="focus")

            obj.style.borderColor="red";

        else if(evt.type=="blur")

           obj.style.borderColor="black";

    }

   </script>



<asp:textbox id="txtFName" runat="server" onfocus="ChangeBorder(this,<br mode=" hold=" /><br mode=" onblur="ChangeBorder(this, event)" xmlns:asp="#unknown">
 
Share this answer
 

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