Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Hiding an ASP.NET Image Control from Javascript

Posted on 2009-06-30
4
Medium Priority
?
278 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 1328 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 1328 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 672 total points
ID: 24745840
0
 

Author Closing Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

916 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