简体   繁体   中英

How I can hide div without using runat server from c# code

I have two conditions, I want to hide and show a div with javascript or with c# code. Using runat="server" , I am able to hide the div with C#. Is it possible to hide the div with javascript? I tried the following:

<div id="divpassword" runat="server" style="display: none;" >
----
----
</div>

document.getElementById('<%= divpassword.ClientID %>').style.display = 'block';

You can use runat="server" and also hide the div from javascript using clientidmode="static" .

<div id="divpassword" runat="server" clientidmode="static" style="display: none;" >
----
----
</div>

document.getElementById('divpassword').style.display = 'block';

It can be very easily done if you use jQuery.

$( "#divpassword" ).hide();

And if you need to do it in pure java script, the following link might help - Show/hide 'div' using JavaScript

You can go many ways.

Way #1:

<div id="divpassword" runat="server" style="display: none;" >
----
----
</div>
<script language="javascript">document.getElementById('<%= divpassword.ClientID %>').style.display = 'block';</script>

Way #2:

<div id="divpassword" runat="server" clientidmode="static" style="display: none;" >
----
----
</div>
<script language="javascript">document.getElementById('divpassword').style.display = 'block';</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM