在VS中怎么实现运行后实现页面跳转,代码如下。关键是输入相应的数据后没有反应!

[复制链接]
查看11 | 回复3 | 2011-2-25 10:28:28 | 显示全部楼层 |阅读模式
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
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)

{

string ConnectionString = "Data Source=.;Initial Catalog=user_info;Integrated Security=True";

SqlConnection conn = new SqlConnection(ConnectionString);

SqlCommand cmd = new SqlCommand();

cmd.Connection = conn;

string sql = "select * from login_infor where username='{0}' and password='{1}'";

sql = string.Format(sql, this.TextBox1.Text, this.TextBox2.Text);

cmd.CommandText = sql;

string role = "";

conn.Open();

SqlDataReader reader = cmd.ExecuteReader();

if (reader.Read())

{

role = reader.GetString(2);

if (role == "admin")

{

Response.Redirect("~/admin.aspx"); //if user's information is right, login successful

}

if (role == "user")

{

Response.Redirect("~/Default2.aspx"); //if user's information is right, login successful

}

}

else

{

Label3.Text = "user name or password is wrong";//if user's information is wrong, can't login

}

conn.Close();

}

protected void Button2_Click(object sender, EventArgs e)

{

Response.Redirect("~/register.aspx");

}
}
数据库为user_info
表名为login_infor
我运行后没有任何反应

回复

使用道具 举报

千问 | 2011-2-25 10:28:28 | 显示全部楼层
拖一个label控件,让它取得登录用户身份(USER或ADMIN)的值然后使用session对象来保存和判定,这才是正规路线
回复

使用道具 举报

千问 | 2011-2-25 10:28:28 | 显示全部楼层
protected void Button2_Click(object sender, EventArgs e)
{
string gh = this.TextBox1.Text;
string pas = this.TextBox3.Text;
if (datesql.login(gh
回复

使用道具 举报

千问 | 2011-2-25 10:28:28 | 显示全部楼层
看你的程序编写,应该都是在一个文件夹里面吧? 难道你的Default.aspx是在子文件夹中? 如果Default2.aspx , Default.aspx , register.aspx 等等都是在一个文件夹中,跳转时就不需要~/符号.只需要写Response.Redirect("register.aspx");就能进行跳转了.Resp
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行