Results 1 to 6 of 6

Thread: Verify the content of the textbox with multiple buttons on Form

  1. #1
    Join Date
    Jan 2010
    Posts
    62

    Verify the content of the textbox with multiple buttons on Form

    I am beginner in VB.net. I have a FORM with multiple button and one textbox. I wish that when I click on the button, we check if something has been entered in textbox. But how to check this? Should I have below code for each button? :
    Code:
    If textbox.text = "" Then
    messageBox.show("Empty Fields")
    Is there a way to do this for all buttons ?

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Verify the content of the textbox with multiple buttons on Form

    Thank you to perform a little research on the forum, this same question comes up several times a week. Here is an example on a button
    Code:
    PrivateSub ManagementOfButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_1.Click, Button_1.Click, Button_2.Click, Button_3.Click, .......

  3. #3
    Join Date
    Jan 2010
    Posts
    62

    Re: Verify the content of the textbox with multiple buttons on Form

    Another problem arose: when I click on the button, the error message, but the action when the button is even launched. Here is my function:

    Code:
    Private Sub ManagementOfButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click, button2.Click
            If TextBox1.Text.Length < 5 Then
                MessageBox.Show("Thank you to comment")
            End If
    End Sub

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Verify the content of the textbox with multiple buttons on Form

    What action? At what point in your code? For there in your code I see too

    If you talk to any code you place after your End If
    Code:
    If ..... Then
      MsgBox("YourMsg")
    End If
    If you do not want to go into "Your Action" to add an else if your

  5. #5
    Join Date
    Jan 2010
    Posts
    62

    Re: Verify the content of the textbox with multiple buttons on Form

    SUB takes into account several buttons. If there is nothing in the textbox, type a message MessageBox.Show ("please save ...") but it is not the action of the start button, type EXIT, but it works not.

    I cannot put the ELSE, because SUB manages several buttons

    Here's the code:
    Code:
    Private Sub ManagementOfButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click, button2.Click
            If TextBox1.Text.Length < 5 Then
                MessageBox.Show("Thank you to comment")
            End If
    End Sub
     
    'button 1
    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
    webrowser.navigate(TextBox1.Text)
    End Sub
     
    'button 2
    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
    webrowser.navigate(TextBox1.Text)
    End Sub

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    Re: Verify the content of the textbox with multiple buttons on Form

    I do not see what prevents you from doing this:
    Code:
    Private Sub ManagementOfButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click, button2.Click
            If TextBox1.Text.Length < 5 Then
                MessageBox.Show("Thank you to comment")
            Else
                webrowser.navigate(TextBox1.Text)
            End If
    End Sub

Similar Threads

  1. Mass Effect 3 Promo Content form 7 Barnes and Noble
    By Elwoody in forum Video Games
    Replies: 7
    Last Post: 19-03-2012, 11:18 PM
  2. Replies: 2
    Last Post: 20-08-2010, 01:23 AM
  3. RegEx - verify content and size
    By New ID in forum Software Development
    Replies: 5
    Last Post: 04-02-2010, 01:27 AM
  4. Problem of html form with multiple submit buttons
    By ASHER in forum Software Development
    Replies: 4
    Last Post: 20-10-2009, 05:31 PM
  5. Several submit buttons in the same form ?
    By Wiro in forum Software Development
    Replies: 5
    Last Post: 14-02-2009, 10:29 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,263,911.08340 seconds with 17 queries