Click here to Skip to main content
14,735,364 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I have a simple VB.Net application.

There are two textboxes:

- TeacherResult
- TeacherInput

One button:

- AddTeacher

After the click on AddTeacher: The input of the user in the TeacherInput textbox will show the input in the TeacherResult textbox.

TeacherResult.Text = "The name of the teacher is: " & TeacherInput.Text

The TeacherInput is cleared with TeacherInput.Text = ""

If the input is empty and the AddTeacher button is clicked the program give a warning. But also after the input of the user the program give a warning, because the TeacherInput is cleared after the button click.

How can I solve this in a good way?

My code

    Private Sub AddTeacher_Click(sender As Object, e As RoutedEventArgs) Handles AddTeacher.Click

        If TeacherInput.Text = "" Then
            WarningText.Visibility = Windows.UI.Xaml.Visibility.Visible
            WarningText.Text = "There is no input"
            TeacherResult.Text = "The name of the teacher is: " & TeacherInput.Text
        End If
        TeacherInput.Text = ""

    End Sub
End Class

Sorry for my bad English.

Thanks in advance.

What I have tried:

Search on Microsoft website and Google search
Updated 12-Nov-20 8:59am
Richard Deeming 12-Nov-20 12:10pm
We can't tell you how to fix your code without seeing the relevant parts of your code.
CHill60 12-Nov-20 12:38pm
Use the "Improve Question" link to share the code from the button click
Gerry Schmitz 12-Nov-20 13:20pm
I think you have to show what's happening in your "click handler".
Coder4EU 12-Nov-20 13:28pm
Thank you for the replies.

Sorry I forget to add my code. I have changed my post.
CHill60 12-Nov-20 14:02pm
I've just tried your code and am not getting the warning if there is text in the box. Do you have any other code that might fire that warning? Are you double-clicking the button?
Try putting a breakpoint on
If TeacherInput.Text = "" Then
and step through the code to see what is happening
Coder4EU 13-Nov-20 12:46pm
It seems there was a bug in my event handler. I replaced my event handler and the code is working fine. Thank you for all the help.

1 solution

You have to reset the warning visibility each time you click; so the first statement / default should be to hide the message, then check.

It happens so fast, there is no benefit to "reusing a message" if that's what you're thinking.

Your option, I assume, is Collapsed. I find that warning text blocks that "pop up" below the offending content aren't disruptive. This means things like a TextBox and Warning in the same stack panel, for example, with the warning collapsed by default.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900