text box label backcolor change on the fly

Hello,
i have a form in which there are labels and text boxes.
Now wha I am tring to do is when there is focus on a text box(user starts to enter text) back color of text box and label should be changed?
how do we that any code?
Asp.net VS2005
Sanjay
dontnetsanjayAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hongjunCommented:
In the onfocus event, try this

TextBox1.BackColor = System.Drawing.Color.Red;
0
udhayakumardCommented:
        private void textBox1_Enter(object sender, EventArgs e)  // Change Color
        {
            textBox1.BackColor = Color.Yellow;
            label1.BackColor = Color.Yellow;
        }

        private void textBox1_Leave(object sender, EventArgs e) // Back to normal
        {
            textBox1.BackColor = Color.Transparent;
            label1.BackColor = Color.Transparent;
        }
0
hongjunCommented:
It should have been "Enter" event.
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

dontnetsanjayAuthor Commented:
Hello again,
in my aspx file when i click on text box and then press F4 propeties of that textbox are displayed
and when i switch to event part it does not display any enter or leave event
i typed this code in my aspx.cs file but nothing is happening
thanks
0
udhayakumardCommented:
U need to add attributes for the text box

/Server Code
txtName.Attributes.Add("onfocus", "textBox1_Enter();")

txtName.Attributes.Add("onblur", "textBox1_Leave();")

//Client Side Code
function SomeJavaScriptFunction(){
//Hi it's txtName's lost focus calling
//Hi txtName :)
}
0
udhayakumardCommented:
Just add this in ur page load

txtEmail.Attributes.Add( "onFocus", "this.style.backgroundColor='aliceblue';" );
  txtEmail.Attributes.Add( "onBlur", "this.style.backgroundColor='white';" );
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dontnetsanjayAuthor Commented:
protected void Page_Load(object sender, EventArgs e)
    {
        TxtCompany.Attributes.Add("onfocus", "txtCompany_Enter();");
         txtCompany.Attributes.Add("onblur", "txtCompany_Leave();");
    }


    private void txtCompany_Enter(object sender, EventArgs e)  
    {
        TxtCompany.BackColor = Color.Yellow;
        lblmsg.BackColor = Color.Yellow;
    }


these lines are givin error when we click on the text box
0
udhayakumardCommented:
k forget that sanjay try this

txtEmail.Attributes.Add( "onFocus", "this.style.backgroundColor='aliceblue';" );
  txtEmail.Attributes.Add( "onBlur", "this.style.backgroundColor='white';" );
0
udhayakumardCommented:
protected void Page_Load(object sender, EventArgs e)
    {
        TxtCompany.Attributes.Add("onfocus", "txtCompany_Enter()");
         txtCompany.Attributes.Add("onblur", "txtCompany_Leave()");
    }


    private void txtCompany_Enter()  
    {
        TxtCompany.BackColor = Color.Yellow;
        lblmsg.BackColor = Color.Yellow;
    }

        private void textBox1_Leave() // Back to normal
        {
            textBox1.BackColor = Color.Transparent;
            label1.BackColor = Color.Transparent;
        }
0
dontnetsanjayAuthor Commented:
txtEmail.Attributes.Add( "onFocus", "this.style.backgroundColor='aliceblue';" );
okay this works


but when we call function  there is till error in the code
error is: object expected
0
udhayakumardCommented:
I dnt think there is a problem in this... May be u check someother part of the code. Else comment this and check...
0
dontnetsanjayAuthor Commented:
txtEmail.Attributes.Add( "onFocus", "this.style.backgroundColor='aliceblue';" );

this part is working fine if we only need to change color of the text box and when we do not want to change color of the label
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.