登錄成功後,我如何從登錄頁面重定向到主頁? 我有一個數據庫,它存儲用戶名和密碼。 在登錄時它將通過sql查詢來檢查用戶名和密碼。 我的代碼如下所示。頁面重定向
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
Label3.Visible = true;
Label3.Text = "* Required Field";
}
else if (TextBox2.Text == "")
{
Label4.Visible = true;
Label4.Text = "* Required Field";
}
else
{
Label3.Visible = false;
Label4.Visible = false;
userid = TextBox1.Text;
pass = TextBox2.Text;
SqlConnection conn = new SqlConnection("SERVER= server3\\OFFICESERVERS; Initial catalog = Web; Integrated Security = SSPI");
SqlCommand mycmd = new SqlCommand();
mycmd.Connection = conn;
mycmd.CommandText = "SELECT FirstName, LastName, MiddleName, Email, Age FROM web WHERE IsActive=1 AND LoginName='" + userid + "' " + "AND Password='" + pass + "'";
try
{
conn.Open();
mycmd.ExecuteScalar();
SqlDataAdapter da = new SqlDataAdapter(mycmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.Visible=true;
GridView1.DataSource = dt;
GridView1.DataBind();
TextBox1.Text = "";
TextBox2.Text="";
}
finally
{
conn.Close();
conn.Dispose();
}
}
}
我的要求是,如果登錄成功我甲肝從登錄頁面重定向到主頁,而不是GridView控件綁定。 它是如何完成的?
你打敗了我。很好的答案。 – BinaryMisfit 2009-07-14 07:49:30