Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide a div from code (c#)

Tags:

c#

asp.net

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?

like image 493
Anjana Avatar asked Mar 14 '11 10:03

Anjana


People also ask

How do I hide a specific div?

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.

How to show hide div using C#?

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.

How can make div invisible in asp net?

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.


2 Answers

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; } 
like image 183
Bazzz Avatar answered Oct 07 '22 20:10

Bazzz


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.

like image 32
Davide Piras Avatar answered Oct 07 '22 21:10

Davide Piras