Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Add attribute to a dynamically created imagebutton control

Add attribute to a dynamically created imagebutton control

Scheduled Pinned Locked Moved ASP.NET
htmlhelpquestion
6 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CandyMe
    wrote on last edited by
    #1

    for loop { ImageButton img = new ImageButton(); img.ImageUrl = "a.gif"; img.Attributes.Add("onmouseover", "this.src='" + imgMouseOverURL + "'"); } Hello, I have an imagebutton instance dynamically generated. The code works fine except the mouse over effect on the button becomes a big red X everytime my mouse hovers over the image. Does this have something to do with the dynamic generation of my imageButton? On the contrary, if I have an imagebutton available in markup with similar attribute, everything works fine. Please help. Thank you.

    Gerri

    F F 2 Replies Last reply
    0
    • C CandyMe

      for loop { ImageButton img = new ImageButton(); img.ImageUrl = "a.gif"; img.Attributes.Add("onmouseover", "this.src='" + imgMouseOverURL + "'"); } Hello, I have an imagebutton instance dynamically generated. The code works fine except the mouse over effect on the button becomes a big red X everytime my mouse hovers over the image. Does this have something to do with the dynamic generation of my imageButton? On the contrary, if I have an imagebutton available in markup with similar attribute, everything works fine. Please help. Thank you.

      Gerri

      F Offline
      F Offline
      Fred_Smith
      wrote on last edited by
      #2

      try doing a "View source" on the generated page to see what is actually sent down to the browser, and how it differs from the markup code that works I'm not quite sure about your for...loop ? However you're looping, you can't create more than one control with the same ID... Fred

      C 1 Reply Last reply
      0
      • F Fred_Smith

        try doing a "View source" on the generated page to see what is actually sent down to the browser, and how it differs from the markup code that works I'm not quite sure about your for...loop ? However you're looping, you can't create more than one control with the same ID... Fred

        C Offline
        C Offline
        CandyMe
        wrote on last edited by
        #3

        Thank you.

        Gerri

        1 Reply Last reply
        0
        • C CandyMe

          for loop { ImageButton img = new ImageButton(); img.ImageUrl = "a.gif"; img.Attributes.Add("onmouseover", "this.src='" + imgMouseOverURL + "'"); } Hello, I have an imagebutton instance dynamically generated. The code works fine except the mouse over effect on the button becomes a big red X everytime my mouse hovers over the image. Does this have something to do with the dynamic generation of my imageButton? On the contrary, if I have an imagebutton available in markup with similar attribute, everything works fine. Please help. Thank you.

          Gerri

          F Offline
          F Offline
          firozu
          wrote on last edited by
          #4

          CandyMe wrote:

          ImageButton img = new ImageButton(); img.ImageUrl = "a.gif"; img.Attributes.Add("onmouseover", "this.src='" + imgMouseOverURL + "'");

          ImageButton accepts 'ImageUrl' attribute rather than 'Src' attribute which is an attribute for HTML Image. Try modifying your last line of code to--- img.Attributes.Add("onmouseover", "this.ImageUrl='" + imgMouseOverURL + "'"); Hope this works :)

          F 1 Reply Last reply
          0
          • F firozu

            CandyMe wrote:

            ImageButton img = new ImageButton(); img.ImageUrl = "a.gif"; img.Attributes.Add("onmouseover", "this.src='" + imgMouseOverURL + "'");

            ImageButton accepts 'ImageUrl' attribute rather than 'Src' attribute which is an attribute for HTML Image. Try modifying your last line of code to--- img.Attributes.Add("onmouseover", "this.ImageUrl='" + imgMouseOverURL + "'"); Hope this works :)

            F Offline
            F Offline
            Fred_Smith
            wrote on last edited by
            #5

            No, that's not right. The Attribute that that line adds is to the control as it is rendered client-side, and therefore you must use the client-side properties. The original code is right, in that respect.

            C 1 Reply Last reply
            0
            • F Fred_Smith

              No, that's not right. The Attribute that that line adds is to the control as it is rendered client-side, and therefore you must use the client-side properties. The original code is right, in that respect.

              C Offline
              C Offline
              CandyMe
              wrote on last edited by
              #6

              Thank you.

              Gerri

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups