hie guys,

a great supportive sites i have ever seen,

i am facing a simple issue with my login windows form, which i have created, it works fine no issue, but now i want that after successful login user should be automatically redirect to home screen (windows forms) but unfortunaterly i am not finding any solution for this , now what shoud i use and the login form should automatically close after redirettion. pleaase help me . .

private void button_Login_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\jumbo\My Documents\Visual Studio 2010\Projects\testingdatabase\testingdatabase\Database1.mdf;Integrated Security=True;User Instance=True");
            //SqlConnection con = Program.Getconnection;
            //SqlConnection con = Program.Getconnection;
            //SqlConnection con = Program.con;
            //SqlDataReader dr = null;
            //try
            //{
            SqlCommand cmd = new SqlCommand("select * from Login WHERE Username = '" + txtUsername.Text +"' AND Password = '" + txtPassword.Text + "'");
            cmd.Connection = conn;
            conn.Open();
                //dr = cmd.ExecuteReader();
            SqlDataReader re = cmd.ExecuteReader();
                if (re.Read())
                {

                    MessageBox.Show("login success");
                }
                else
                    MessageBox.Show("inavlid username and password");
            }
                    //catch (Exception ex)
            //{
                //MessageBox.Show(ex.Message);
           // }

        }
    }

Recommended Answers

All 3 Replies

How about WelcomeForm.usernameTxb.Text = LoginForm.txtUsername.Text;

its so simple and basic in ASP Dot Net. if user is autherised then create session and then redirect to the page you want like this:

if(tblUserReg.Rows.Count == 1)
{
    Session["userid"] = tblUserReg.Rows[0]["user_id"].tostring();
    Response.Redirect("welcome.aspx");
}

//here tblUserReg is the resultant table retrive from database which have user and pasword correct like textboxes and status is on
//Session["userid"] will have the id as a value which is going to be null when user logout

Please also add a condition on homepage - load event like this:

if(Session["userid"] == null || session["userid"].tostring() == "")
    response.Redirect(login.aspx);

and on logout button click please make the session null and redirect to login page like this:

void onLogoutClick()
{
    session["userid"] = null;
    response.Redirect("login.aspx");
}

Here's one way,

If you show the login form as a dialog, then show it in the start of your main form, you read the dialogresult to either continue or end.

Assign Button_Login as the Accept button, and assign a Cancel button on the login form.

in your authentication code, if the user is authenticated just return, otherwise call the cancel button performclick method

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.