-1

EDIT: Sorry for the lack of information, its a winform app in C# And the post is not duplicate. The problem happens when i close the form witch contains the report to edit the previous form values and then the button to print the report again stays disabled instead of remaining enabled.

I found several similar posts but none resolved my issue. I have the following code do enable a button if a textbox is empty:

button3.Enabled = string.IsNullOrWhiteSpace(resposta.Text);

The code works but the problem is, if i click next and for some reason want to go back to alter something the button stays disabled even with data in the textbox.

Can anyone help?

Thanks in advance

Liam
  • 27,717
  • 28
  • 128
  • 190
MarcIT
  • 39
  • 11
  • "Next" and "go back"? How are you doing this? – MakePeaceGreatAgain Nov 22 '16 at 10:26
  • Add that code to the `TextChanged` event of the textbox you are checking – Pikoh Nov 22 '16 at 10:27
  • I don't even know how you're having this next and go back functionalities, but since the state of the textbox is being changed, I believe a form_Load function is running. Just add this same code to your form_Load – Phiter Nov 22 '16 at 10:27
  • @PhiterFernandes `page_load`? The tag is winforms – Pikoh Nov 22 '16 at 10:28
  • The app runs a formula and gives a result in a textbox then the button "print" is enabled and clicking it prints a report with various data. If i close the form witch contains the report to alter some data the button print stays disabled – MarcIT Nov 22 '16 at 10:28
  • I know, it's not page_load. It's form_load. I got confused – Phiter Nov 22 '16 at 10:29
  • I´,m not sure the duplicate matches. As far as I understand OP he doesn´t change the textbox´ value, instead he´s opening and closing a second form. No idea how this could affect the textbox at all. – MakePeaceGreatAgain Nov 22 '16 at 10:35
  • Are you using the TextChanged event of your textbox? If not, then you should. – Mitulát báti Nov 22 '16 at 10:37
  • Did you tried to add that code to the `TextChanged` event as we have told you? – Pikoh Nov 22 '16 at 10:44
  • Yes, but if i do, the button stays disabled – MarcIT Nov 22 '16 at 10:51
  • Because `resposta.Text` is empty i guess,so that's the expected behavior. Why don't you edit your question and tell us exactly the behavior you expect(i.e. when the button must be enabled and when not) – Pikoh Nov 22 '16 at 10:56

1 Answers1

0

Well, it's a but unclear what the problem is, but it seems you are trying to use WinForms as some MVC with binding (like angular), but when you do assignment it does this one time only in WinForms, no binding is created.

So you need to figure out when you need to call this again. (TextChange, some button click, etc.)

Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207