Mukesh Jha
Mukesh Jha

Reputation: 1

Response.Redirect Doesn't Work in my Windows Forms Application

My page does not redirect to the Page I have specified. While I am doing so it says The name "Response" does not exist in the current context Please also help me with getting the register value in the database while doing the signup.

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace LoginSystem123
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void buttonLogin_Click(object sender, EventArgs e)
        {
            var myConnection = new SqlConnection();
            myConnection.ConnectionString = @"Data Source=mukesh-PC\SQLEXPRESS;Initial       Catalog=testDb;Integrated Security=True;Pooling=False";
            var myCommand = new SqlCommand();

            var cmd = "SELECT * FROM [User] Where [User].Email =" + "'" + textBoxEmail.Text + "'";
            myCommand.CommandText = cmd;
            myCommand.CommandType = CommandType.Text;
            myCommand.Connection = myConnection;

            myConnection.Open();

            var myReader = myCommand.ExecuteReader();

            bool isRegisteredUser = myReader.Read();
            if (isRegisteredUser)
            {
                var PasswordFromDatabase = myReader.GetString(5);

                if (textBoxPassword.Text == PasswordFromDatabase.TrimEnd())
                {
                    MessageBox.Show("Successfully Logged on !");

                }
                else
                {
                    MessageBox.Show("Invalid password. Try again");
                }
            }
            else
            {
                MessageBox.Show("Invalid user");

            }
        }

        /* private void buttonSignUp_Click(object sender, EventArgs e)
        {
            Response.Redirect("SignUp.cs");
        }
        */
        private void buttonSignUp_Click_1(object sender, EventArgs e)
        {
            Response.Redirect("SignUp.cs");
        }
    }
}

Upvotes: 0

Views: 7894

Answers (2)

iceheaven31
iceheaven31

Reputation: 887

Response.Redirect only works for web applications, and it looks like you're coding for Windows application.

You should do this instead:

SignUp su = new SignUp();
su.Show();
this.Hide();

Upvotes: 1

TheEvilPenguin
TheEvilPenguin

Reputation: 5682

Response.Redirect is used to redirect to another page in an ASP website - nothing like this works in Windows Forms.

If SignUp.cs defines a Form, you can do something like this to show it:

var signup = new SignUp();
signup.ShowDialog();

If you let us know more about what you're trying to do, we can probably be a bit more helpful.

Upvotes: 3

Related Questions