Response.Redirect无法跳转?!
在Default.aspx页面放置2个Textbox用来记录用户名和密码,1个TEXT为【Session传值】的Button,点击
按钮时将Default.aspx页面转到Default2.aspx页面并显示刚才输入的用户名和密码
Default.aspx.cs代码
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlconn = new SqlConnection("Data
Source=.\\SqlExpress;Database=HO;Uid=sa;Pwd=");
sqlconn.Open();
SqlCommand sqlcom = sqlconn.CreateCommand();
sqlcom.CommandText = sqlcom.CommandText = "select count(*) from Region where
RegionID='" + TextBox1.Text +
"' and RegionDescription='" + TextBox2.Text + "'";
int count=Convert.ToInt32(sqlcom.ExecuteScalar());
if (count > 0)
{
Session["name"] = TextBox1.Text;
Session["pwd"] = TextBox2.Text;
Response.Redirect("Default2.aspx");//无法跳转、、、、、?!
}
else
{
Response.Write("<script language=javascript>alert('用户名或密码错
误');location='javascript:history.go(-1)</script>");
}
}
}
Default2.asp.cs代码
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["Name"] != null)
{
Response.Write("用Session对象传的用户名为:" + Session["name"].ToString() +
"<br>" + "密码为:" + Session["pwd"].ToString());
}
}
}
}