Solved

Hiding an ASP.NET Image Control from Javascript

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

705 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

18 Experts available now in Live!

Get 1:1 Help Now