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

  • Home
  • SEARCH
  • 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 8740867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:12:27+00:00 2026-06-13T11:12:27+00:00

this is driving me crazy. I have a piece of code on a Windows

  • 0

this is driving me crazy.

I have a piece of code on a Windows Form Control, this code ensures the form clears and put the focus back to the first Control (Phone Number). The problem is I am using On-Leave Event Handles and this handler contain the Validation code so that the Phone is validated when the use leaves the control.

When I hit Reset or Exit of the form, it not only clears the form, it also sends the focus back to the Phone field, causing the control (Textbox) to Validate.

I need the focus on the Phone control with at the validation on focus, is there a way I can prevent this behavior?

private void txtPhone_Leave(object sender, EventArgs e)
        {
             Int64 ConvertPhone;
            if (txtPhone.Text.Trim().Length != 10)
            {
                lblPhoneError.Visible = true;
                lblErrorIndicator.Visible = true;
                lblErrorIndicator.Text = "*Valid 10 digit phone number required";
            }

            else if (Int64.TryParse(txtPhone.Text, out ConvertPhone))
            {
                lblPhoneError.Visible = false;
                lblErrorIndicator.Visible = false;
                txtPhone.MaxLength = 10;
                txtPhone.Text = txtPhone.Text.Substring(0, 3) + "." + txtPhone.Text.Substring(3, 3) + "." + txtPhone.Text.Substring(6, 4);
           }

        }

 private void btnClear_Click(object sender, EventArgs e)
    {
        txtPhone.Clear();
        txtPhone.Focus();
    }


    private void txtPhone_Enter(object sender, EventArgs e)
    {
        txtPhone.Text = txtPhone.Text.Replace(".", "");
    }

Thanks everyone!

  • 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-06-13T11:12:28+00:00Added an answer on June 13, 2026 at 11:12 am

    if (txtPhone.Text.Trim().Length != 10)
    {

                if (txtPhone.Text != "")
                {
                    lblErrorIndicator.Visible = true;
                    lblErrorIndicator.Text = "*Valid 10 digit phone number required";
                }
            }
    

    private void btnClear_Click(object sender, EventArgs e)
    {
    txtPhone.Clear();
    lblErrorIndicator.Text=””;
    txtPhone.Focus();
    }

    I can understand your problem but tell me what you want to do at the end?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me crazy. I have a very simple user control: public int?
this piece of code is driving me crazy. I'm trying to print a help
This is driving me crazy! I have a form and am supposed to do
This one is driving me crazy:-) Lets say I have some test xaml code:
This is driving me crazy. I have a PHP script that gets some data
This is driving me crazy and I can't find the answer anywhere. I have
Ok, this is driving me crazy. I have a CA that needs to know
This has been driving me crazy for the past few minutes I have a
This has been driving me crazy. I think I have everything in place but
Any regex gurus around here? its driving me crazy. Say I have this string:

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.