473,408 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Change imageButton image in a master page

I would like to change the image on animageButton as this is clicked by the user.

when the master page is loaded it shows the btnHome.ImageUrl = "~/images/home.jpg";

But when the user clicks on the btnHome, its ImageUrl should change to btnHome.ImageUrl = "~/images/homeSelected.jpg";

The imageButton should change from a selected image to nonselected.

Thanks so much
May 3 '10 #1
5 4929
I have a master page which included several ImageButtons controls. I would like the image on each of these buttons to change as the user clicks on determined button. For example, the home (button) when clicked will show the image homeSelected.jpg, when is not selected willl show the home.jpg.

Any help on this matter will be greatly appreciated.
May 3 '10 #2
tlhintoq
3,525 Expert 2GB
Please don't double-post your questions. It divides attempts to help you in an organized and cohesive manner. Your threads have been merged
May 3 '10 #3
Frinavale
9,735 Expert Mod 8TB
The way I see it you have a couple of options.
You could either access the home button in the MasterPage from your Content Page and set the image accordingly...or you could check the URL in the master page and set the image accordingly.

I think the first way makes the most sense: leave the responsibility up to the content page since instead of having a huge if/else (or switch/select-case) in your master page.

To access the button in the master page you would use the FindControl method.
Something like this:
(vb.net)
Expand|Select|Wrap|Line Numbers
  1. CType(Master.FindControl("btnHome"), ImageButton).ImageUrl = "~/images/homeSelected.jpg"
(c#)
Expand|Select|Wrap|Line Numbers
  1. (ImageButton)Master.FindControl("btnHome").ImageUrl = "~/images/homeSelected.jpg";
-Frinny
May 3 '10 #4
@Frinavale
Thanks alot for your help!!! I came up with the following code and it works right.
Expand|Select|Wrap|Line Numbers
  1.         ImageButton myImageButton = new ImageButton();
  2.         protected void Page_Load(object sender, EventArgs e)
  3.         {
  4.             myImageButton = (ImageButton)Master.FindControl("btnHome");
  5.             if (myImageButton.ImageUrl == "~/images/home.jpg")
  6.             {
  7.                 myImageButton.ImageUrl="~/images/homeSelected.jpg";
  8.             }
  9.         }
May 4 '10 #5
Frinavale
9,735 Expert Mod 8TB
:) Glad I could help :)

-Frinny
May 4 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: blarfoc | last post by:
I am using the ImageButton to represent tabs on my webform. I have 5 tabs. Each tab can have 2 images. A clicked imaagge and a unclicked image. When I click on a image that is not clicked I...
0
by: Lanny | last post by:
I have a web site with client side scripting that used to work fine until I put all the pages in a master page. Now none of the client scripting works. I have done some reading and learned about...
4
by: Mark Olbert | last post by:
I have a website (ASPNET2) where the master page has a button in it and my login page, which is a detail page of the master page, also has a button (a login button). Everything works fine if I...
3
by: Mark Olbert | last post by:
I have some img tags on a master page which reference files in a top-level directory. They look like this: <img src="assets/test.gif" id="gnr" /> assets is a subdirectory of the website root. ...
2
by: Miguel Dias Moura | last post by:
Hello, The pages on my web site use a master page. In my master page I have an Asp:Image. The Asp:Image has the same properties and position in all pages which is defined in my master page. ...
4
by: David Lozzi | last post by:
Howdy, I have my master page, and I would like to change the background CSS class per the content page. Only the home page has a different background style, all other pages are using the same. I...
5
by: 3Dfelix | last post by:
I have a problem when using a Master page file in diferent aspx files. Some of this aspx are in different places. I have see that the problem is with styles definition on master file, when use...
4
by: JimHeavey | last post by:
If on my master page I have an image which is in the image folder. For web pages which are in the "default" directory, the image displays just fine. But if one of my pages which "utilizes" the...
2
by: brettokumar | last post by:
hi im using master page when im click lang btn like english in my aspx form at run time caption values are change in my aspx form only but not change in my master page control caption wat can i do...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.