Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7616475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:53:50+00:00 2026-05-31T02:53:50+00:00

A form has many buttons. One of those buttons contains code to update the

  • 0

A form has many buttons. One of those buttons contains code to update the TableAdapterManager. One of the many TextBox controls has code in a Validating event handler. There is code to make sure a US phone number is formatted properly.

If the user tabs out of the TextBox the Validating code works perfectly and show a message to the user if the phone number is not properly formatted and the focus is place in the offending TextBox.

If the user clicks on a button that has code to update the TableAdapterManager the Validating code fires but instead of focus remaining on the offending TextBox, the code in the button Click handler also fires.

I would like to stop the button code from firing.

Here is the code for the Validating event of the TextBox:

Private Sub TextBoxPrimaryPhone_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBoxPrimaryPhone.Validating

    ' Make sure the phone is formatted correctly.
    '--------------------------------------------
    If PhoneFormat(TextBoxPrimaryPhone.Text) = "Fix Phone Number" Then

        ' Alert the user.
        '----------------
        MessageBox.Show("Please enter a 7 or 10 digit phone number.", _
                        "Entry Error", _
                        MessageBoxButtons.OK, _
                        MessageBoxIcon.Error)

        e.Cancel = True
    Else

        ' Format according to the length of the phone number entered by the user.
        '------------------------------------------------------------------------
        TextBoxPrimaryPhone.Text = PhoneFormat(TextBoxPrimaryPhone.Text)
    End If
End Sub

What additional coding to I need to include so focus remains on the TextBox?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:53:52+00:00Added an answer on May 31, 2026 at 2:53 am

    After e.Cancel = True is called do this to set the focus of the offending textbox:

    TextBoxPrimaryPhone.Focus()
    

    In your button click event handler you can do this:

        TextBoxPrimaryPhone_Validating(sender, New System.ComponentModel.CancelEventArgs)
    
        If Not TextBoxPrimaryPhone.Focused Then
    
            'Do Work
    
        End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have WPF Form which has many buttons with the same code. Appearance of
I have a workbook that has many checkboxes (form control) on one tab. I
if one part of one form of our app has many views - let's
I have a form that has many long-methods. My quest is: What is the
My page is a bulk order form that has many products and various size
I need to create a form that has many of the same fields, that
My form has several numeric up down controls. All of these controls, when changed,
I have a complex form that has a static section and one that can
Using a WinApp form in c#, and many buttons here... I want to create
I have a Content model which has one or many Audio files which need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.