Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

text box label backcolor change on the fly

Posted on 2007-09-07
12
Medium Priority
?
1,788 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:dontnetsanjay
  • 6
  • 4
  • 2
12 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 19852367
In the onfocus event, try this

TextBox1.BackColor = System.Drawing.Color.Red;
0
 
LVL 11

Expert Comment

by:udhayakumard
ID: 19852370
        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
 
LVL 33

Expert Comment

by:hongjun
ID: 19852372
It should have been "Enter" event.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:dontnetsanjay
ID: 19852415
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
 
LVL 11

Expert Comment

by:udhayakumard
ID: 19852454
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
 
LVL 11

Accepted Solution

by:
udhayakumard earned 1000 total points
ID: 19852468
Just add this in ur page load

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

Author Comment

by:dontnetsanjay
ID: 19852482
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
 
LVL 11

Expert Comment

by:udhayakumard
ID: 19852485
k forget that sanjay try this

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

Expert Comment

by:udhayakumard
ID: 19852488
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
 

Author Comment

by:dontnetsanjay
ID: 19852503
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
 
LVL 11

Expert Comment

by:udhayakumard
ID: 19853129
I dnt think there is a problem in this... May be u check someother part of the code. Else comment this and check...
0
 

Author Comment

by:dontnetsanjay
ID: 19857333
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The viewer will learn how to dynamically set the form action using jQuery.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question