473,699 Members | 2,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

image button rollover

i am trying to create a simple image button rollover.. i have
searched this forum and found a number of solutions but none seem to
work. i am just trying to get the onmouseover to swap the image then
restore when rolled out on a web page in vb.net. please can someone
help?

Mar 14 '07 #1
2 8792
On Mar 14, 6:25 am, "smokeyd" <tom_bur...@umb ro.co.ukwrote:
i am trying to create a simple image button rollover.. i have
searched this forum and found a number of solutions but none seem to
work. i am just trying to get the onmouseover to swap the image then
restore when rolled out on a web page in vb.net. please can someone
help?
I did it on the server side, while I was setting up the page. Most of
my pages have an OK button and a Cancel button. For consistency's
sake, the images are all named the same. That is, the standard buttons
end in ".jpg" and the hover style ends in "_hover.jpg ".

We use ImageButton controls to represent buttons so that we can
respond to click events server-side. When I'm designing the form, I
always only set the ImageUrl property, and I always only set it to the
*unhovered* image.

I wrote a method in the page's base class called SetButtonImages , that
looks something like this:

Protected Sub SetButtonImages (ByVal button As ImageButton)

Dim imageUrl As String

imageUrl = button.imageUrl

' Set the image that appears when the user moves the mouse off
' of the button.
image.Attribute s.Add("onmouseo ut", "src=""" & imageUrl & """")

' Remove the .jpg extension, and add the "_hover.jpg " extension
imageUrl = imageUrl.SubStr ing(0, imageUrl.Length - 4)
imageUrl &= "_hover.jpg "

' Set the image that appears when the user hovers the mouse
' over the image button.
button.Attribut es.Add("onmouse over", "src=""" & imageUrl & """")

End Sub

(WARNING: I'm recalling this from memory, since the boss just tweaked
our firewall, and I can't peak at the source code to refresh my
memory, so I'm sorry if there are bugs.)

The method is invoked in the derived pages, like this:

Protected Sub PageLoad(ByVal sender As Object, ByVal e As EventArgs)
Handles Page.Load
...
SetButtonImages (btnOk)
SetButtonImages (btnCancel)
End Sub

This implementation saved me a lot of time, but it's based on a base
class for your pages. If you're not using a base class, you can simply
put the SetButtonImages function in a sepraate class, or even in a
module and invoke it from there (so that you don't have to repeat it
in every page). Once you have that method working the way you want it
to, it becomes highly reusable. You can change the file extension to
match whatever image types or file names you're using.

The caveat, of course, is that you have a consistent image naming
scheme. You can, of course, change the arguments to the method to pass
in the names of the images. That simplifies the entire task, and is
likely far more reliable if your file names aren't consistent. (A lack
of consistency doesn't mean anything--it's a frequent phenomenon, and
just indicates that the images likely came from disparate sources.)

I hope this helps!

Mike

Mar 14 '07 #2
On 14 Mar, 10:58, "Mike Hofer" <kchighl...@gma il.comwrote:
On Mar 14, 6:25 am, "smokeyd" <tom_bur...@umb ro.co.ukwrote:
i am trying to create a simple image button rollover.. i have
searched this forum and found a number of solutions but none seem to
work. i am just trying to get the onmouseover to swap the image then
restore when rolled out on a web page in vb.net. please can someone
help?

I did it on the server side, while I was setting up the page. Most of
my pages have an OK button and a Cancel button. For consistency's
sake, the images are all named the same. That is, the standard buttons
end in ".jpg" and the hover style ends in "_hover.jpg ".

We use ImageButton controls to represent buttons so that we can
respond to click events server-side. When I'm designing the form, I
always only set the ImageUrl property, and I always only set it to the
*unhovered* image.

I wrote a method in the page's base class called SetButtonImages , that
looks something like this:

Protected Sub SetButtonImages (ByVal button As ImageButton)

Dim imageUrl As String

imageUrl = button.imageUrl

' Set the image that appears when the user moves the mouse off
' of the button.
image.Attribute s.Add("onmouseo ut", "src=""" & imageUrl & """")

' Remove the .jpg extension, and add the "_hover.jpg " extension
imageUrl = imageUrl.SubStr ing(0, imageUrl.Length - 4)
imageUrl &= "_hover.jpg "

' Set the image that appears when the user hovers the mouse
' over the image button.
button.Attribut es.Add("onmouse over", "src=""" & imageUrl & """")

End Sub

(WARNING: I'm recalling this from memory, since the boss just tweaked
our firewall, and I can't peak at the source code to refresh my
memory, so I'm sorry if there are bugs.)

The method is invoked in the derived pages, like this:

Protected Sub PageLoad(ByVal sender As Object, ByVal e As EventArgs)
Handles Page.Load
...
SetButtonImages (btnOk)
SetButtonImages (btnCancel)
End Sub

This implementation saved me a lot of time, but it's based on a base
class for your pages. If you're not using a base class, you can simply
put the SetButtonImages function in a sepraate class, or even in a
module and invoke it from there (so that you don't have to repeat it
in every page). Once you have that method working the way you want it
to, it becomes highly reusable. You can change the file extension to
match whatever image types or file names you're using.

The caveat, of course, is that you have a consistent image naming
scheme. You can, of course, change the arguments to the method to pass
in the names of the images. That simplifies the entire task, and is
likely far more reliable if your file names aren't consistent. (A lack
of consistency doesn't mean anything--it's a frequent phenomenon, and
just indicates that the images likely came from disparate sources.)

I hope this helps!

Mike
works a treat!

thanks very much for that mike, it works great. cant beleive it is so
difficult in .net though!

many thanks for your help.

Mar 14 '07 #3

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

Similar topics

5
2950
by: Richard | last post by:
I'm beginning to undertake php for the fun of it. Working on a problem I hope can be solved in php. Basically what I have is this: <body> <img name="main" src="image1.jpg"> <a href="#" onMouseOver="document.main.src='image2.jpg'"
15
3070
by: Applebrown | last post by:
I've got a couple of errors on my site that I'm not sure how to fix. I'm using simple CSS for both text rollovers and my horizontal navbar, and here's what happens. First, the site: www.sunbadgeco.com/sunmetal/index.htm #1 { In IE6, rolling over an image in the navbar makes it "light" up. Clicking on the image takes you to another page (which is not finished). Then clicking the Back button keeps the image you just clicked on "lit" up,...
1
3046
by: Dave | last post by:
Hi all, I was trying to make an image submit button with a rollover and discovered to my suprise that there is no way to access a form element of the "image" type. I tried specifying it by name and also by the elements array with no luck. Even weirder, I can sandwich an image button in between other input types and then write a script diplaying the contents of the elements array and it acts as if the image button does not exist at all!...
1
10269
by: Frances Del Rio | last post by:
I have a form in which submit button is an img.. would like to do it w/a rollover, but can't get rollover to work.. can you do rollovers w/img submit buttons? this is code I have: <input type="image" name="log" src="images/login.gif" value="Submit" alt="Submit" onMouseover = "log.src='images/login-roll.gif'" onMouseout ="images/log.src='login.gif'"> thank you..
7
2457
by: simchajoy2000 | last post by:
Hi, I am just a javascript beginner so maybe this is a simple problem but I am trying to do some rollovers on images in a separate <div>. Here is the relevent piece of my code: <html> <head> <script type="text/javascript"> if (document.images) {
1
3009
by: trint | last post by:
Hi, I have an Image to become a link (as soon as I figure out whether it should be a button or not) that, when mousedover, changes instantly to another image. I want the image itself to be the link. How can I do that please. Any help is appreciated. Thanks, Trint
2
3441
by: Casimir | last post by:
I am looking into making pure CSS image rollovers. Do you have any clever (and robust) CSS rollover-tricks? Or links to such "in the wild"? I have figured out two methods for this, but have yet to do proper testing on browser support. Method I:
2
1579
by: mrking | last post by:
Before I go ahead and implement this I need to confirm that what I want can be done. The standard image rollover works well, however this time I want to modify it to show the current selected button as the rollover would be until the next menu item is clicked. IE, lets say I have two buttons Company Contact non active state has the image text in grey, rolled over image text is red.
0
8703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8623
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
9185
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
9050
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...
1
8935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6540
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
5879
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();...
1
3069
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
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.