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 8612453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:37:47+00:00 2026-06-12T04:37:47+00:00

I have a login form and a button which check if the user name

  • 0

I have a login form and a button which check if the user name and the password are true.
but the problem is the code I tried .. I must click on the connect button twice.

but the code should work when I click on the button just once ! Right ?

I think the problem is: the showDialog won’t be disappeared if only I click in some button that it’s DialogResult set in some value, so in the first click the connexionButton.DialogResult gets the DialogResult.OK value and in the second click the button executes the code.

*you can notice that the event simpleButton1_Click is the event for the connexionButton Button*

this is the event I used :

  this.connexionButton.Click += new System.EventHandler(this.simpleButton1_Click);

this is the code I tried :

private void simpleButton1_Click(object sender, EventArgs e)
{
     Boolean allowCnx = false;

     foreach (var row in myClass.ds.Tables["Users"].AsEnumerable())
     {
         if (row[1].ToString().ToLower() == idBox.Text.ToLower() && row[2].ToString().ToLower() == mdpBox.Text.ToLower())
         {
            allowCnx = true;
         }
     }

     if (allowCnx)
     {
         connexionButton.DialogResult = DialogResult.OK;
     }
     else
       XtraMessageBox.Show("Invalide Information", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

and this is the code I used to call this login form :

using (login loginForm = new login())
{
     var result = loginForm.ShowDialog();
     if (result == DialogResult.OK)
        this.Show();
     else
        this.Close();
}
  • 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-12T04:37:48+00:00Added an answer on June 12, 2026 at 4:37 am
    // Points to a different method than the one you posted
    // (simpleButton1_Click_1 instead of simpleButton1_Click)
    this.simpleButton1.Click += new System.EventHandler(this.simpleButton1_Click_1);
    
    // This isn't simpleButton1_Click_1
    private void simpleButton1_Click(object sender, EventArgs e)
    

    Not sure if that is your issue, but it looks like your event handler is a different method than the one you posted. Do you have another method called simpleButton1_Click_1 somewhere in your code and you’ve just gotten slightly confused?

    EDIT: In response to your changes/additions

    You seem to have some confusion over ShowDialog and DialogResult.

    // When you launch the login form, I do not know what you intended to do with your
    // calls to Show() and Close() but so long as you don't instend for them to do
    // anything to the loginForm, that's fine.
    using (login loginForm = new login())
    {
        if (loginForm.ShowDialog() == DialogResult.OK)
            // Do stuff if logged in
        else
            // Do stuff if failed
    } 
    
    private void simpleButton1_Click(object sender, EventArgs e)
    {
        Boolean allowCnx = false;
    
        foreach (var row in myClass.ds.Tables["Users"].AsEnumerable())
            if (row[1].ToString().ToLower() == idBox.Text.ToLower() && row[2].ToString().ToLower() == mdpBox.Text.ToLower())
            {
                allowCnx = true;
            }
    
        if (allowCnx)
        {
            this.DialogResult = DialogResult.OK; // Don't set the DialogResult of a button.  Set it for the form.
        }
        else
        {
            this.DialogResult = DialogResult.Abort; // Because we didn't succeed
            XtraMessageBox.Show("Invalide Information",
                "Erreur",
                MessageBoxButtons.OK,
                MessageBoxIcon.Error);
        }
    }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a login form from which the user enters user name and password.
I have a login form that has Username and password as inputs from user
i have a user login form. i which the user is requested to input
I have a login form which sends 3 post values from username, password and
I have a registration form in which i have a field login name. I
I have this button which submits the login form: <input class=btn btn-large btn-success id=login-button
I have a login form which appears at the top of all of my
I have a login form, which needs to be re-directed to the main page
Hi I have created the code below to check if a user is valid
I have a form on my .jsp page which sends a password back to

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.