Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
am facing small issue

here once fill all fields after that navigate to another page means index page to index2 page here where we write code redirect() method please reply me

or any mistakes please reply me
C#
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    
}
private void Redirect()

{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    SqlCommand cmd = new SqlCommand("select * from SignUpTable where Username=@Username and Password=@Password", con);
    cmd.Parameters.AddWithValue("@Username", txtEmailAddress.Text);
    cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);

    if (dt.Rows.Count > 0)
    {
        DataRow dr = dt.Rows[0];
        Session["Username"] = dr["Username"].ToString();
        Response.Redirect("Index2.aspx");
    }
}
protected void btnSignup_Click(object sender, EventArgs e)
{
    int userId = 0;
    string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("SP_SignUpTable"))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@FirstName"", txtFirstName.Text.Trim());
                cmd.Parameters.AddWithValue("@LastName", txtLastName.Text.Trim());
                cmd.Parameters.AddWithValue("@Username",txtEmailAddress.Text.Trim());
                cmd.Parameters.AddWithValue("@Password", txtCreatePassword.Text.Trim());
                cmd.Parameters.AddWithValue("@ConfirmPassword", txtConfirmPassword.Text.Trim());
                cmd.Parameters.AddWithValue("@MobileNumber", txtMobilenumber.Text.Trim());
                cmd.Parameters.AddWithValue("@Area", txtResearch.Text.Trim());
                cmd.Parameters.AddWithValue("@DateOfBirth", txtDOB.Text.Trim());
                cmd.Parameters.AddWithValue("@Gender", RadioButtonList1.Text.ToString());
                cmd.Connection = con;
                con.Open();
                userId = Convert.ToInt32(cmd.ExecuteScalar());
                con.Close();
            }
        }
        string message = string.Empty;
        switch (userId)
        {
            case -1:
                message = "Username already exists.\\n Please choose a different username.";
                break;
            case -2:
                message = "Supplied Email address has already been used.";
                break;
        }

        ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
    }
}
private void Clear()
{
    txtFirstName.Text = txtLastName.Text = txtEmailAddress.Text = txtPassword.Text = txtConfirmPassword.Text = txtMobilenumber.Text = txtResearch.Text = " ";
}
protected void btnLogin_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    con.Open();
    SqlCommand cmd = new SqlCommand("select * from SignUpTable where Username=@Username and Password=@Password", con);
    cmd.Parameters.AddWithValue("@Username", txtEmail.Text);
    cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);

    if (dt.Rows.Count > 0)
    {
        DataRow dr = dt.Rows[0];
        Session["Username"] = dr["Username"].ToString();
        Response.Redirect("Home Page.aspx");
    }
    else
    {
        ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script launguage='javascript'>alert('Invalid Email and Password')</script>");
    }
}
}


[Edit member="Tadit"]
Added pre tags.
[/Edit]
Posted
v3
Comments
Laiju k 21-Oct-14 1:08am    
what is the error you are getting
member10000 21-Oct-14 1:12am    
Dear Laiju,

error means here not navigating
member10000 21-Oct-14 1:14am    
Dear Laiju ,
please reply me what mistake and where we write redirect method please reply me
member10000 21-Oct-14 1:31am    
Dear Laiju,
please reply me please
Sinisa Hajnal 21-Oct-14 2:26am    
You're not calling your redirect anywhere...what are you trying to do?

1 solution

C#
if (dt.Rows.Count > 0)
{
    DataRow dr = dt.Rows[0];
    Session["Username"] = dr["Username"].ToString();
    Response.Redirect("Index2.aspx");
}

Couple of things to note here.

  1. Debug and see whether any Rows are returned or not.
  2. See if Index2.aspx is in the same directory as this Page.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900