Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NET
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 16 Dec '12 - 23:23
ntitish946

Comments
Rahul K Singh - 17 Dec '12 - 5:47
I guess you need some kind of CSS which will do all this.
Zaf Khan - 18 Dec '12 - 22:59
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)

4 solutions

Write this under TextChanged Event..
if(TextBox1.Text == string.Empty)
{
   TextBox1.Backcolor = Color.Red;
}
else
{
   TextBox1.Backcolor = Color.Green;
   TextBox1.Forecolor = Color.White;
}
  Permalink  
Comments
ntitish - 17 Dec '12 - 5:36
Sir i had so many text boxes in my registration and in web site.......cant we change in designing part.
Krunal Rohit - 17 Dec '12 - 5:38
not getting you clearly...
ntitish - 17 Dec '12 - 5:51
its ok sir i got my answer.thanks
Krunal Rohit - 17 Dec '12 - 6:01
If you're satisfied with the given answer, Accept the Solution :) -Krunal R.
Try following
 
<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
  Permalink  
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

.MyTextStyle
{
  Color: #FF0000;
  Background-color: #FFFFFF;
}
 

The style below gives you Black background and white text

.MyTextStyle:Hover
{
  Color: #FFFFFF;
  Background-color: #0000;
}
 
This is probably the BEST way to do it
  Permalink  
<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">
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,376
1 OriginalGriff 6,571
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid