LogoASPAlliance: Articles, reviews, and samples for .NET Developers
A rollover image user control
by Chris Garrett
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 19805/ 21

A rollover image user control
A rollover image user control
by Chris Garrett

A common user interface task for web developers and designers is to create buttons on a page that react when you roll your mouse pointer over them. This is a simple thing to do, but can cause a lot of "copy and paste" reuse. This project shows how to do it the way ..

To achieve a rollover effect (swap the image when the mouse is over) you need a hyperlink, an image and some client side script. This is very easy to do by using response.write, but to make it more "ASP.NET webforms" we use server controls.

View page source

In the ASPX file we set up our HyperLink and Image. Now check out the codebehind .vb file where we set the Image and HyperLink URLs. We also set two attributes to the HyperLink of onMouseOver and onMouseOut. These are our client side scripts.

See it in action

User Control

We have our rollover working but it is not very reusable. The following code puts the project inside a user control allowing us to set the image src and urls as properties.

view control source

The following ASPX embeds the control into a page, setting the various properties.

View test page source

See it in action

A very simple control, but it demonstrates how to neatly add client side interface logic into a page.





Product Spotlight
Product Spotlight 

©Copyright 1998-2021  |  Page Processed at 2021-12-04 8:42:30 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search