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
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]