Solved

Hiding an ASP.NET Image Control from Javascript

Posted on 2009-06-30
4
258 Views
Last Modified: 2012-05-07
Hello everyone!

Got a really irritating problem that just wont quit.

I am trying to hide an <asp:image> control from javascript.

What I basically have are the following three components

asp:ImageMap
asp:RectangleHotSpot
asp:Image

Now, the asp:Image is an overlay to the ImageMap.  It starts with Visible set to false.
When the user clicks the RectangleHotSpot, I want to make the asp:image visible.

I have setup my asp:ImageMap to use HotSpotMode="Navigate".
The asp:RectangleHotSpot has the navigation url set to "javascript:flipImageVisibility('1');"

Each hotspot will have its own value that it imputs into the flipImageVisibility function.

The javascript function is defined below in the code part.

What essentially happens is that document.getElementById always returns null.  I have tried using the exact id, as well as the objectid.ClientID.  Both always return null.

Anyone know what could possibly be wrong?

Thanks!
function flipImageVisibility(id) {
			        
			        switch (id) {
			            case "1":
			                document.getElementById('<%=imgOverlay1.ClientID%>').Visible = 
! document.getElementById('<%=imgOverlay1.ClientID%>').Visible;
			                break;
			        }
			        
			    }

Open in new window

0
Comment
Question by:recruitit
  • 2
4 Comments
 
LVL 15

Assisted Solution

by:mohan_sekar
mohan_sekar earned 332 total points
ID: 24745797
It's style.visibility - document.getElementById('<%=imgOverlay1.ClientID%>').style.visibility
0
 
LVL 15

Assisted Solution

by:mohan_sekar
mohan_sekar earned 332 total points
ID: 24745824
and, you need to check for 'visible' or 'hidden'. It doesn't work like a boolean field.

like this
case "1":
                                  if (document.getElementById('<%=imgOverlay1.ClientID%>').style.visibility == 'visible')
document.getElementById('<%=imgOverlay1.ClientID%>').style.visibility = 'hidden';
else
document.getElementById('<%=imgOverlay1.ClientID%>').style.visibility = 'visible';

                                  break;


You can optimize the code
0
 
LVL 8

Accepted Solution

by:
lharrispv earned 168 total points
ID: 24745840
0
 

Author Closing Comment

by:recruitit
ID: 31598354
I used style.display = 'none' in the end.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question