How to hide a div from code (c#)

前端 未结 9 1550
迷失自我
迷失自我 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:12

    work with you apply runat="server" in your div section...

    <div runat="server" id="hideid">
    

    On your button click event:

     protected void btnSubmit_Click(object sender, EventArgs e)
        {
          hideid.Visible = false;
        }
    
    0 讨论(0)
  • 2020-12-01 04:14

    one fast and simple way is to make the div as

    <div runat="server" id="MyDiv"></div>
    

    and on code behind you set MyDiv.Visible=false

    0 讨论(0)
  • 2020-12-01 04:14

    Try this. Your markup:

    <div id="MyId" runat="server">some content</div>
    

    .. 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;
        }
    }
    
    0 讨论(0)
提交回复
热议问题