amit
amit

Reputation: 449

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';

Upvotes: 1

Views: 1699

Answers (3)

procma
procma

Reputation: 1440

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>

Upvotes: 0

Yogi
Yogi

Reputation: 9739

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

Upvotes: 0

Rubysmith
Rubysmith

Reputation: 1175

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';

Upvotes: 2

Related Questions