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?
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;
}
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
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;
}
}