what you are trying to do is difficult.
when you set src="images/buttonPressed.gif", you are telling the browser to
download a new image are change the display of the object. when the object
is a imagebutton, the onclick is firing a postback, which is also a download
request. becuase the main page is being replaced, the gif download is
canceled.
to do what you want if you really want to:
1) precache the "button pressed image"
<script>
var imgButtonPressed = new Image ();
imgButtonPressed.src = "images/buttonPressed.gif";
</script>
2) on the image buttons click cancel the postback, change the image and
queue up a new submit.
<script>
function onClick(e)
{
if (e.src != img.src) {
e.src = img.src; // use cached image
var s = "document.getElementById('" + e.id + "').click()";
window.setTimeout(s,10); // give enough time to display
image before real postback
return false;
}
return true;
}
</script>
3) in the code behind, add the onclick handler
button.Attributes.Add("onclick","return onClick(this);")
-- bruce (sqlwork.com)
"Prescott Chartier" <pc*******@yahoo.com> wrote in message
news:87**************************@posting.google.c om...
David,
What I need to know is how to change the image on the imagebutton
to simulate the button being pressed down just before the postback
event is fired. I used the script below to change the image on the
MouseDown event (client side), but instead of changing the image to
the "button presed" image, the button disappeared just before the
postback event was fired. Why would that happen?? Or is there an
order to the events firing that I'm not aware of?
Any assistance would be gratefully appreciated.
Prescott ...
"Davide Vernole [MVP]" <da****@online.knodev.com> wrote in message
news:<e2**************@TK2MSFTNGP15.phx.gbl>...
ruca <ru***@iol.pt> typed: Right. My question is how??????????????????????????????????
JavaScript it's not my strong....
Put this in your aspx page
<script language='javascript'>
<!--
function EvImageOverChange(name, direction)
{
switch(direction)
{
case 'in':
name.src = "image/OverImage.gif";
break;
case 'out':
name.src = "image/InitialImage.gif";
break;
}
}
//-->
</script>
in the code behind insert this in the Page load method:
if(!IsPostBack)
{
myImageButton.ImageUrl = "image/InitialImage.gif";
myImageButton.Attributes["OnMouseOver"] =
"javascript:EvImageOverChange(this, 'in');";
myImageButton.Attributes["OnMouseOut"] =
"javascript:EvImageOverChange(this, 'out');";
}
where myImageButton is your WebControls of type ImageButton,
InitialImage.gif is you initial image and OverImage.gif is the image
displayed when the OnMouseOver event is fired.
HTH