求助。NET的

来源:百度知道 编辑:UC知道 时间:2024/06/08 10:13:07
protected void Page_Load(object sender, EventArgs e)
{
string a = Request["txtmath1"];
Label1.Text = a.ToString();
}
这是用户登入跳转的页,我想在Label显示用户名,怎么会未将对象引用设置到对象的实例?这是第一页,
if (!IsPostBack)
{
string a = Request["txtmath1"].ToString();
string b = Request["txtmath2"].ToString();

SqlConnection con = new SqlConnection("server=.;database=login;uid=sa;pwd=50820419;");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*)from login where userName='" + a + "'and userpwd='" + b + "'", con);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
Response.Redirect("main.aspx");
}

Response.Redirect("main.aspx?txtmath1=" + a);

你在Redirect的时候并没有传值啊。应该用Response.Redirect("main.aspx?txtmath1=" + a); 另外,用户登入跳转的页你应该还加个判断。
protected void Page_Load(object sender, EventArgs e)
{
if(Request["txtmath1"]!=null)
{
string a = Request["txtmath1"].ToString();
Label1.Text = a.ToString();
}
}