locked
How to check for empty textbox on button click and force user to fill the textbox RRS feed

  • Question

  • Hello guys!!

    i am working on a program, and on my form i have a couple of textboxes and radio buttons. I have a next button on my form to. I want my program to run in such a way that, when the Next button is clicked, it checks for any empty textbox and forces the user to fill the textbox.

    Using vb.net 2012. 

    Im sorry if my questions may not be technical enough for this forum, but any form of help will be appreciated immensely

    Saturday, March 8, 2014 9:10 PM

Answers

  •     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            If TextBox1.Text = "" Then
                MessageBox.Show("Text cannot be empty, fill in before proceeding", _
                                "User Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                TextBox1.Focus()
            End If
        End Sub
    


    • Proposed as answer by Mr. Monkeyboy Saturday, March 8, 2014 9:57 PM
    • Marked as answer by Diepriye Sunday, March 9, 2014 6:33 PM
    Saturday, March 8, 2014 9:24 PM

All replies

  •     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            If TextBox1.Text = "" Then
                MessageBox.Show("Text cannot be empty, fill in before proceeding", _
                                "User Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                TextBox1.Focus()
            End If
        End Sub
    


    • Proposed as answer by Mr. Monkeyboy Saturday, March 8, 2014 9:57 PM
    • Marked as answer by Diepriye Sunday, March 9, 2014 6:33 PM
    Saturday, March 8, 2014 9:24 PM
  • Thanks it worked for me.
    Saturday, March 8, 2014 9:32 PM
  • Thanks it worked for me.

    The you should propose Devons post as the answer to close the thread. I did it but you need to do it to make the answered area of the post blue meaning either you or a moderator say it was the correct answer.


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


    Saturday, March 8, 2014 9:56 PM
  • You can also do this too.

    If String.IsNullOrEmpty(TextBox1.Text) Then

        do something

    endif

    Sunday, March 9, 2014 4:09 AM