Click here to Skip to main content
13,201,763 members (71,616 online)
Rate this:
 
Please Sign up or sign in to 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 16-Dec-12 23:23pm
ntitish1.9K
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)
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  
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 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 17-Dec-12 5:38am
   
not getting you clearly...
ntitish 17-Dec-12 5:51am
   
its ok sir i got my answer.thanks
Krunal Rohit 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  

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 |
Web04 | 2.8.171020.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2017
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