How to hide a div from code (c#)

前端 未结 9 1673
迷失自我
迷失自我 2020-12-01 03:38

I have a div element on my page that I wish to show/hide based on a session value in my code-behind. How can I do this?

9条回答
  •  星月不相逢
    2020-12-01 04:14

    Try this. Your markup:

    some content

    .. and in aspx.cs file:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["someSessionVal"].ToString() == "some value")
        {
            MyId.Visible = true;
        }
        else
        {
            MyId.Visible = false;
        }
    }
    

提交回复
热议问题