473,915 Members | 4,402 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 8807
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
2963
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
3110
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
3061
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
10281
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
2469
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
3018
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
3456
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
1592
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
10039
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
9881
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
10923
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
11066
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,...
0
10542
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...
0
7256
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
5943
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3368
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.