Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:23pm
ntitish1.4K
Comments
Rahul K Singh at 17-Dec-12 5:47am
   
I guess you need some kind of CSS which will do all this.
Zaf Khan at 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)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 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.
Krunal Rohit at 17-Dec-12 5:38am
   
not getting you clearly...
ntitish at 17-Dec-12 5:51am
   
its ok sir i got my answer.thanks
Krunal Rohit at 17-Dec-12 6:01am
   
If you're satisfied with the given answer, Accept the Solution :)
-Krunal R.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

<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  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,108
1 OriginalGriff 8,186
2 CPallini 2,613
3 Richard MacCutchan 2,231
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
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