本人在Page_Load里写了一个Session,但是不行,首次运行会有错误...怎么改一下?我的意思是先进来判断有没有,如果有就执行东西,没有就不执行,
我想让一个按钮,然后通过这个按钮写入Session,然后刷新本页,然后来执行Session要执行的这些东西
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
if(Session["login"].ToString() == "login")
{
this.username.Visible=false;
this.pass.Visible=false;
this.password.Visible=false;
this.logname.Text = Session["username"].ToString();
this.cent.Text = Session["cent"].ToString();
this.usercent.Visible=true;
}
}
// 在此处放置用户代码以初始化页面
}下面有一个Buttonprivate void Submit1_ServerClick(object sender, System.EventArgs e)
{
string sql="select count(username) from users where username = '"+username.Text.Trim()+"' and userpassword = '"+password.Text.Trim()+"'";
long count=Convert.ToInt32(DAOHelper.ExecuteScalar(sql));
if(count>0)
{
string str = "select usename,cent from users where username = '"+username.Text+"' and userpassword = '"+password.Text+"'";
OleDbConnection cn=null;
OleDbDataReader dr=DAOHelper.ExecuteReader(str,ref cn);
if(dr.Read())
{
try
{
//dr.Close();
//cn.Close();
Session["login"] = dr["username"];
username.Text = "";
password.Text = "";

}
catch
{
dr.Close();
cn.Close();
}
}
Page.RegisterStartupScript("","<script>window.location.href='down.aspx'</script>");
}