Solved

Hiding an ASP.NET Image Control from Javascript

Posted on 2009-06-30
4
252 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now