Change imageButton image in a master page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danmoran
    New Member
    • May 2010
    • 14

    #1

    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.ImageUr l = "~/images/home.jpg";

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

    The imageButton should change from a selected image to nonselected.

    Thanks so much
  • danmoran
    New Member
    • May 2010
    • 14

    #2
    Modify imageButton.Ima geUrl in a master page

    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.jp g, when is not selected willl show the home.jpg.

    Any help on this matter will be greatly appreciated.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Please don't double-post your questions. It divides attempts to help you in an organized and cohesive manner. Your threads have been merged

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        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...o r 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)
        Code:
        CType(Master.FindControl("btnHome"), ImageButton).ImageUrl = "~/images/homeSelected.jpg"
        (c#)
        Code:
        (ImageButton)Master.FindControl("btnHome").ImageUrl = "~/images/homeSelected.jpg";
        -Frinny

        Comment

        • danmoran
          New Member
          • May 2010
          • 14

          #5
          Originally posted by Frinavale
          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...o r 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)
          Code:
          CType(Master.FindControl("btnHome"), ImageButton).ImageUrl = "~/images/homeSelected.jpg"
          (c#)
          Code:
          (ImageButton)Master.FindControl("btnHome").ImageUrl = "~/images/homeSelected.jpg";
          -Frinny
          Thanks alot for your help!!! I came up with the following code and it works right.
          Code:
                  ImageButton myImageButton = new ImageButton();
                  protected void Page_Load(object sender, EventArgs e)
                  {
                      myImageButton = (ImageButton)Master.FindControl("btnHome");
                      if (myImageButton.ImageUrl == "~/images/home.jpg")
                      {
                          myImageButton.ImageUrl="~/images/homeSelected.jpg";
                      }
                  }
          Last edited by Frinavale; May 4 '10, 01:17 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            :) Glad I could help :)

            -Frinny

            Comment

            Working...