Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / September 2004

Tip: Looking for answers? Try searching our database.

Change image of imagebutton

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ruca - 02 Sep 2004 10:16 GMT
Hi gurus,
I have a imagebutton in my WebForm, and I want that when I click (mouse
down) on her the imagebutton change image and when I "unclick" (mouse up)
change to the original image.
Basically I want to know how can I have the mousedown and mouseup buttons
events. I think that I have to do this in JavaScript.

Can you help me on this?

Signature

Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

avnrao - 02 Sep 2004 11:04 GMT
yes. the best way to achieve is to write a simple javascript method and
change the image url.

Av.
> Hi gurus,
> I have a imagebutton in my WebForm, and I want that when I click (mouse
[quoted text clipped - 4 lines]
>
> Can you help me on this?
ruca - 02 Sep 2004 11:45 GMT
Right. My question is how??????????????????????????????????
JavaScript it's not my strong....

Signature

Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

> yes. the best way to achieve is to write a simple javascript method and
> change the image url.
[quoted text clipped - 8 lines]
> >
> > Can you help me on this?
Davide Vernole [MVP] - 02 Sep 2004 12:00 GMT
ruca <ruuca@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

Signature

Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer

Prescott Chartier - 30 Sep 2004 19:14 GMT
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 ...

> ruca <ruuca@iol.pt> typed:
> > Right. My question is how??????????????????????????????????
[quoted text clipped - 35 lines]
>
> HTH
bruce barker - 30 Sep 2004 21:08 GMT
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)

> David,
>
[quoted text clipped - 49 lines]
> >
> > HTH

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.