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?
We hide the divs by adding a CSS class called hidden to the outer div called . text_container . This will trigger CSS to hide the inner div.
show or hide <div>content</div> using C# If you want to use div, you have to use JavaScript to achieve it. In the below codes, Button1 will show div and Button2 will hidden div. If you want to use C#, you can achieve it via RegisterStartupScript: Page.
You can hide (not render) SCRIPT tags by wrapping them in a DIV tag, making that runat="server", then setting its visible property to false in the code-behind.
Give the div "runat="server"
and an id
and you can reference it in your code behind
.
<div runat="server" id="theDiv">
In code behind:
{ theDiv.Visible = false; }
if your div has the runat set to server, you surely can do a myDiv.Visible = false
in your Page_PreRender
event for example.
if you need help on using the session, have a look in msdn, it's very easy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With