Changing image on an ImageButton makes by button disappear

A

abarberis

I am writing an asp.net application which is using image buttons for
the interface. I have some buttons that have a enabled and disabled
state. I have written javascript code to change the image on the button
when it is disabled. Below is a snippet:

document.all.btnSignIn.src="Images/sign_in_disabled.gif";

This code correctly changes the image on the button. The problem is
that sometimes if you push the button, it will turn white almost as if
it is waiting to download the image. The page moves too quickly for it
to ever show the disabled version. However, you still see the button
"disappear" for a second before the new page loads.

I have tried to place a hidden version of the disabled image on the
site thinking it might force a download and cache it locally.

Anyone have an idea on how I can make the image switch instantly?
Thanks

Alex
 
B

bruce barker

you are correct, its downloading the image. to cache it, in javascript
create a Image object.

<script>
var disabledImage = new Image()
disabledImage.src = "Images/sign_in_disabled.gif";
</script>

later:

document.getElementById("btnSignIn").src = disabledImage.src;

-- bruce (sqlwork.com)


| I am writing an asp.net application which is using image buttons for
| the interface. I have some buttons that have a enabled and disabled
| state. I have written javascript code to change the image on the button
| when it is disabled. Below is a snippet:
|
| document.all.btnSignIn.src="Images/sign_in_disabled.gif";
|
| This code correctly changes the image on the button. The problem is
| that sometimes if you push the button, it will turn white almost as if
| it is waiting to download the image. The page moves too quickly for it
| to ever show the disabled version. However, you still see the button
| "disappear" for a second before the new page loads.
|
| I have tried to place a hidden version of the disabled image on the
| site thinking it might force a download and cache it locally.
|
| Anyone have an idea on how I can make the image switch instantly?
| Thanks
|
| Alex
|
 
A

Alex

Bruce,

I tried your suggestion but I am experiencing the same behavior. As far
as I can tell setting the disabledImage.src =
"Images/sign_in_disabled.gif"; stores a URL in the variable. I think
this is the same as setting the ImageButton.src...
Any ideas?

Thanks

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top