473,657 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change image of imagebutton

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?

--
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
Nov 18 '05 #1
6 22121
yes. the best way to achieve is to write a simple javascript method and
change the image url.

Av.
"ruca" <ru***@iol.pt > wrote in message
news:ut******** *****@TK2MSFTNG P11.phx.gbl...
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?

--
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

Nov 18 '05 #2
Right. My question is how???????????? ??????????????? ???????
JavaScript it's not my strong....
--
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" <av*@newsgroups .com> escreveu na mensagem
news:OM******** ******@TK2MSFTN GP09.phx.gbl...
yes. the best way to achieve is to write a simple javascript method and
change the image url.

Av.
"ruca" <ru***@iol.pt > wrote in message
news:ut******** *****@TK2MSFTNG P11.phx.gbl...
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?

--
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


Nov 18 '05 #3
ruca <ru***@iol.pt > typed:
Right. My question is how???????????? ??????????????? ???????
JavaScript it's not my strong....


Put this in your aspx page

<script language='javas cript'>
<!--
function EvImageOverChan ge(name, direction)
{
switch(directio n)
{
case 'in':
name.src = "image/OverImage.gif";
break;
case 'out':
name.src = "image/InitialImage.gi f";
break;
}
}
//-->
</script>

in the code behind insert this in the Page load method:

if(!IsPostBack)
{
myImageButton.I mageUrl = "image/InitialImage.gi f";
myImageButton.A ttributes["OnMouseOve r"] =
"javascript:EvI mageOverChange( this, 'in');";
myImageButton.A ttributes["OnMouseOut "] =
"javascript:EvI mageOverChange( this, 'out');";
}

where myImageButton is your WebControls of type ImageButton,
InitialImage.gi f is you initial image and OverImage.gif is the image
displayed when the OnMouseOver event is fired.

HTH

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer
Nov 18 '05 #4
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******* *******@TK2MSFT NGP15.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='javas cript'>
<!--
function EvImageOverChan ge(name, direction)
{
switch(directio n)
{
case 'in':
name.src = "image/OverImage.gif";
break;
case 'out':
name.src = "image/InitialImage.gi f";
break;
}
}
//-->
</script>

in the code behind insert this in the Page load method:

if(!IsPostBack)
{
myImageButton.I mageUrl = "image/InitialImage.gi f";
myImageButton.A ttributes["OnMouseOve r"] =
"javascript:EvI mageOverChange( this, 'in');";
myImageButton.A ttributes["OnMouseOut "] =
"javascript:EvI mageOverChange( this, 'out');";
}

where myImageButton is your WebControls of type ImageButton,
InitialImage.gi f is you initial image and OverImage.gif is the image
displayed when the OnMouseOver event is fired.

HTH

Nov 18 '05 #5
It might be that IE stops loading images once a new page request (such as a
postback) occurs. You could use the interval timer in client-side code to
cause a delay before the postback by returning false to prevent the form
being submitted and then calling the submit method in your code. But this
will break the page if the user has scripting disabled or not supported. You
might find some useful client-side scripting tricks like this at:
http://www.daveandal.net/books/6744/samples.aspx
Nov 18 '05 #6
what you are trying to do is difficult.

when you set src="images/buttonPressed.g if", 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 imgButtonPresse d = new Image ();
imgButtonPresse d.src = "images/buttonPressed.g if";
</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.getEl ementById('" + e.id + "').click() ";
window.setTimeo ut(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.Attribut es.Add("onclick ","return onClick(this);" )

-- bruce (sqlwork.com)

"Prescott Chartier" <pc*******@yaho o.com> wrote in message
news:87******** *************** ***@posting.goo gle.com...
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******* *******@TK2MSFT NGP15.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='javas cript'>
<!--
function EvImageOverChan ge(name, direction)
{
switch(directio n)
{
case 'in':
name.src = "image/OverImage.gif";
break;
case 'out':
name.src = "image/InitialImage.gi f";
break;
}
}
//-->
</script>

in the code behind insert this in the Page load method:

if(!IsPostBack)
{
myImageButton.I mageUrl = "image/InitialImage.gi f";
myImageButton.A ttributes["OnMouseOve r"] =
"javascript:EvI mageOverChange( this, 'in');";
myImageButton.A ttributes["OnMouseOut "] =
"javascript:EvI mageOverChange( this, 'out');";
}

where myImageButton is your WebControls of type ImageButton,
InitialImage.gi f is you initial image and OverImage.gif is the image
displayed when the OnMouseOver event is fired.

HTH

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2705
by: Ester | last post by:
Instead of drag and drop image button from Toolbox and name the image button id on the properties box, I would like to load image button ID from database. I created a database table that stores Image Button ID and Image (path name of the image for the image button). Example of the data will be: (ImgBtnLight, image\light.gif). The data type of the Image Button ID field in the database table is varchar whereas data type of image button in...
1
2420
by: Holly | last post by:
Hi, I have a page (A) that allows users to enter addresses and displays direction information and map images. The page A calls Microsoft's mappoint web service, gets the route info and map image. Page A contains an image button with the image url set as MapOutput.aspx <asp:imagebutton id="ibtnMap" runat="server" ImageUrl="MapOutput.aspx"></asp:imagebutton> After page A got the image, it stores the image into
4
2607
by: Andy G | last post by:
I am tring to loop through a dataset to find records that exist. If the record exists then make the corresponding image visible. So I try to take the row value and concatenate it onto a string ("imgSession"), so the resulting control ID name will be imgSessionX. Where X could be a number corresponding to the ID of the image. I need help with the logic. Dim row As DataRow Dim myImage As Image
3
3905
by: jens.buchta | last post by:
Hi! I'm using a DataGrid with a template column to display an Image inside of it. I'm hooking into its OnPrerender-Event to set the ImageURL-Property dynamically. Everything works just fine here, until I thought "It would be cool, if the user could click on that image..". So I replaced the Image-Control with an ImageButton. My Problem is, that the ImageButton doesn't fire any events. Any other
5
2624
by: Varangian | last post by:
Hi there experts, Is there a way to convert a System.Drawing.Image to an ImageButton. Maybe using ChangeType I don't know! Thank you
10
2381
by: Edwin Knoppert | last post by:
I have an asp.net imagebutton with a clickevent. I have enclosed an anchor around the image and a small text. If i click the image the event is executed (while the href of the anchor shows in the statusbar) If the user clicks the image or the text beneat it it should do the same, executing the image asp.net server event. I can manage this fine using javascript but the href must contain a character to get the mousehand.
1
2486
by: Brett Wesoloski | last post by:
I am having problems getting the index of an image click event in a datagrid. Every time I look at the index it is -1. What I am trying to do is get the index of the row in which the imagebutton was clicked. So that I can then go and look into a hidden field as to what the value will be that I need to use. I am using a template column to create the imagebutton. <asp:TemplateColumn HeaderText="">
4
2040
by: vamshiv | last post by:
hi...im working on asp.net with VB i have created a database which hav fields id,name,image path in web form i hav written code for creation of image buttons dynamically i hav connected the form to DB and got the table into DataSet and also i hav placed one panel which contains image and label controls for dynamic image buttons i hav given the image URL from table only. and i hav written addHandler method to hanling events But for...
3
5244
by: Ganesh | last post by:
Hi There, Could you some tell me the difference between Image and ImageButton, which one do i need to use if i want to show some picture on the html Thanks Ganapathi
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.