初学.NET,某块区域,通过Session得知用户登入后,我想要让某些控件不显示,比如Lable,textbox,要怎么做?
如果使用VS2005里的login,loginview控件,又要怎么做,登入的账户名,密码都在数据表中,能不能给段代码,SQLEXPRESS的?
如果使用VS2005里的login,loginview控件,又要怎么做,登入的账户名,密码都在数据表中,能不能给段代码,SQLEXPRESS的?
{
this.Label1.Visible = false;
}
{
this.Label1.Visible = false;
}else
{
this.Label1.Visible = true;
}楼上用了三元运算符代码简单理解不简单,就像一楼那样直接判断
{
string randomcode = Request.Cookies["randomcode"].Value;
string code = TextBox3.Text;
if (code.Equals(randomcode, StringComparison.OrdinalIgnoreCase))
{
SqlConnection con = new SqlConnection("server=localhost;database=moldsystem;uid=sa;pwd=sa");
con.Open();
string sql = "select * from data_user where user_name='" + TextBox1.Text + "' and user_pass='" + TextBox2.Text + "'";
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
if (DropDownList1.Text == "tooling_cost查询系统")
{
Session["user_name"] = TextBox1.Text;
Response.Redirect("Default.aspx");
}
else
{
//Label11.Text = Convert.ToString(Session["username"]);
Session["user_name"] = TextBox1.Text;
Response.Redirect("fukuanchaxun.aspx");
}
}
else
{
Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
Response.Write("登陆账号或密码错误!!");
}
}
else
{
Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
Response.Write("验证码错误!!");
} }
textbox1.Visible=Session["user"]==null?true:false;if(Session["username"]!=null)
{
this.Label1.Visible = false;
}else
{
this.Label1.Visible = true;
}
如果是想把空间隐藏 把display=none
(1) visible=false;
(2) style=“display:none”
(3) style="visibility:hidden"
具体的区别,楼主可以自己尝试。