Solved

Hiding an ASP.NET Image Control from Javascript

Posted on 2009-06-30
4
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do i use the await event in php echo 5 44
PHP $_POST vs asp request 4 57
Where is this content coming from? 4 40
ajax post without refreshing whole page 10 22
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 …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

752 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