Share via

If textboxes are empty, how do I disable a button?

Tim 60 Reputation points
2024-01-15T16:23:47.9233333+00:00

I have a button connected to textboxes. How do I disable the button if textboxes are empty? I've tried a few things, cannot seem to get it to function. Thanks.

Developer technologies | Windows Forms
Developer technologies | .NET | Other
Developer technologies | VB
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other

A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.

0 comments No comments

Answer accepted by question author

Viorel 127K Reputation points
2024-01-15T17:13:15.1866667+00:00

For instance, handle the TextChanged event of textboxes. (The handlers can be added by double-clicking the textboxes). Also handle the Load event of the form.

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        UpdateButton()
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        UpdateButton()
    End Sub

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
        UpdateButton()
    End Sub

    Sub UpdateButton()
        Button1.Enabled = Not String.IsNullOrWhiteSpace(TextBox1.Text) AndAlso Not String.IsNullOrWhiteSpace(TextBox2.Text)
    End Sub

It is possible to use a unique TextChanged handler for textboxes.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.