初学.NET,某块区域,通过Session得知用户登入后,我想要让某些控件不显示,比如Lable,textbox,要怎么做?
如果使用VS2005里的login,loginview控件,又要怎么做,登入的账户名,密码都在数据表中,能不能给段代码,SQLEXPRESS的?

解决方案 »

  1.   

    if(Session["username"]!=null)
    {
       this.Label1.Visible = false;
    }
      

  2.   

    textbox1.Visible=Session["user"]==null?true:false;
      

  3.   

    if(Session["username"]!=null)
    {
      this.Label1.Visible = false;
    }else
    {
      this.Label1.Visible = true;
    }楼上用了三元运算符代码简单理解不简单,就像一楼那样直接判断
      

  4.   

    登录protected void Button1_Click(object sender, EventArgs e)
        {
            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("验证码错误!!");
            }    }
      

  5.   

    三元运算符 就是一个 if  else
      

  6.   


    textbox1.Visible=Session["user"]==null?true:false;if(Session["username"]!=null)
    {
      this.Label1.Visible = false;
    }else
    {
      this.Label1.Visible = true;
    }
      

  7.   

    如果只是不显示  把visable=false
    如果是想把空间隐藏  把display=none
      

  8.   

    visible属性啊,true就显示,false就是不显示
      

  9.   

    建议楼主如果想继续.NET的学习的话,可以先去看看MSDN上的视频。或者买点学习的资料看看。(关于那个login控件的使用方法,那个视频中都是有的)隐藏控件的方法,
    (1) visible=false;
    (2) style=“display:none”
    (3) style="visibility:hidden"
    具体的区别,楼主可以自己尝试。
      

  10.   

    控件.visible=true;控件.visible=false;