登录后如何禁止某项功能?
我做一个网页,主页上有,A,B,C,D,四个linkbutton,点击能进入相应板块,其中D是专门为会员准备的,管理员是不能看到的,我就想实现管理员进行登录,登陆成功进入E页面,在E页面上点击“回到主页”,管理员无法操作D,因此想管理员登陆后把D设成enable的false就行,以下是代码,就是实现不了,请大侠指点如何改进:
首页登录button代码:
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "Data Source=localhost;Initial Catalog=电影信息交流系统;Integrated Security=True";
try
{
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
if ("会员" == DropDownList1.Text)
{
this.LinkButton1.Visible = true;
cmd.CommandText = "select * from 用户信息表 where 注册用户名 = '" + TextBox1.Text + "'and 密码='" + TextBox2.Text + "'";
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Redirect("欢迎会员.aspx");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script>alert('错误!请重新输入');</script>");
}
dr.Close();
}
else if ("管理员" == DropDownList1.Text)
{
cmd.CommandText = "select * from 管理员表 where 管理员用户名 = '" + TextBox1.Text + "'and 密码='" + TextBox2.Text + "'";
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
//登陆成功
this.HyperLink2.Enabled = false;///////////////////////////////////////加在这里不行
Response.Redirect("欢迎管理员.aspx");
}
else
{
//登陆不成功
// MessageBox.Show("错误!请重新输入用户名或密码!");
Response.Write("<script>alert('错误!请重新输入用户名或密码!!')</script>");
}
dr.Close();
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
cn.Close();
}