Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BackColor and Enabled Properties of Textbox

Status
Not open for further replies.

JabbaTheNut

Programmer
Jul 29, 2002
176
US
I have a dropdown list named "mySelect" that has three items indexed as 0,1,2.
I also have a textbox named "myTextBox".
I want myTextBox to be disabled and grayed out when mySelect.SelectedIndex=0
I am using the following code-behind which is attached to a "Submit" button on the web form...

If mySelect.SelectedIndex = 0 then
myTextBox.Text = ""
myTextBox.BackColor = System.Drawing.Color.Gray
myTextBox.Enabled = False
End If

The problem is as follows:

If the user selects mySelect.SelectedIndex = 1 (or 2) and clicks the Submit button, myTextBox.Text does not change to "" (as expected); however, myTextBox.BackColor does change to gray and myTextBox is disabled (not supposed to happen).

I thought my setup seemed fairly straight forward. But I am clearly missing something here. Why is the textbox color changing and the control becoming disabled when item 0 is not selected? Please help. Thanks :) Game Over, Man!
 
heh heh.

You ready to kick yourself?

So the page loads, and index 0 is selected by default, right? So the back color is greyed out, and the enabled = false.

Well, if they select 1 or 2, unless you have code somewhere else that you didn't post, you never change the color BACK to white or set the enabled property to TRUE.

So all you'd need is to add

Else
myTextBox.BackColor = System.Drawing.Color.White
myTextBox.Enabled = True


Problem solved
:)

jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top