how to display none through code behind
Asked Answered
D

6

37

I have tried this

login_div.Style("display") = "none";

But it's not working.how can I set the display of the div to none through code behind, in aspx I have a div:

<div id="login_div" runat="server">
Deshabille answered 10/12, 2009 at 16:9 Comment(4)
If you set the css to display: none; then it won't display. I don't understand what your asking.Sacttler
@earlz: It won't display initially, but it can be changed with Javascript.Adelaideadelaja
actually i want to do it in codebehind fileDeshabille
why do you want to do this in code behind? Could you better explain the situation?Motte
J
72

I believe this should work:

login_div.Attributes.Add("style","display:none");
Juieta answered 10/12, 2009 at 16:11 Comment(0)
G
16

Try if this works:

Panel2.Style.Add("display", "none");
Glossography answered 18/10, 2012 at 5:22 Comment(0)
C
4

try this

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

and on the code behind.

login_div.Style.Add("display", "none");

Careerism answered 17/6, 2010 at 13:0 Comment(0)
S
2
if(displayit){
  login_div.Style["display"]="inline"; //the default display mode
}else{
  login_div.Style["display"]="none";
}

Adding this code into Page_Load should work. (if doing it at Page_Init you'll have to contend with viewstate changing what you put in it)

Sacttler answered 10/12, 2009 at 16:26 Comment(0)
M
1

Since this is a login div, shouldn't the default be to NOT display it. I am going to go ahead and assume then you want to display it then via javascript.

<div id="login" style="display:none;">Content</div>

Then using jQuery:

<script type="javascript">$('#login').show();</script>

Another method you might consider is something like this:

<div id="login" style="display:<%=SetDisplay() %>">Content</div>

And the SetDisplay() method output "none" or "block"

Motte answered 10/12, 2009 at 16:24 Comment(0)
B
0
div_id.Attributes.Add("style","display:none");

div_id: id which you want to hide.

Attributes: that will use value.

Add: keyword will add the attribute.

Style: is the attribute.

and last one is the name and value of the attribute

Bezanson answered 24/3, 2022 at 18:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.