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. Adding Events to Web User Controls

Adding Events to Web User Controls

Scheduled Pinned Locked Moved ASP.NET
questionwinforms
4 Posts 3 Posters 0 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.
  • O Offline
    O Offline
    Os Sutrisno
    wrote on last edited by
    #1

    I have created a user control with an image and a label in it. I want to add an event when the user control is clicked to change the back color of the label (within the user control). How can I achieve this? Thanks! :)

    J 1 Reply Last reply
    0
    • O Os Sutrisno

      I have created a user control with an image and a label in it. I want to add an event when the user control is clicked to change the back color of the label (within the user control). How can I achieve this? Thanks! :)

      J Offline
      J Offline
      Javier Lozano
      wrote on last edited by
      #2

      You can do this with javascript. Add an onclick attribute to the <span> that encapsulates your control and tie it to a javascript function. In the function, then set the backcolor of the label. Doing it this way, you eliminate the postback to your page. Does that work for you? ~Javier Lozano

      O 1 Reply Last reply
      0
      • J Javier Lozano

        You can do this with javascript. Add an onclick attribute to the <span> that encapsulates your control and tie it to a javascript function. In the function, then set the backcolor of the label. Doing it this way, you eliminate the postback to your page. Does that work for you? ~Javier Lozano

        O Offline
        O Offline
        Os Sutrisno
        wrote on last edited by
        #3

        It will work for me i suppose. But i've seen a few articles that can do in all within .Net. It just that I don't get it =( I was hoping that someone would be kind enough to guide me. Oh well, back to reading them articles i guess! Thanks!

        S 1 Reply Last reply
        0
        • O Os Sutrisno

          It will work for me i suppose. But i've seen a few articles that can do in all within .Net. It just that I don't get it =( I was hoping that someone would be kind enough to guide me. Oh well, back to reading them articles i guess! Thanks!

          S Offline
          S Offline
          srinivas s
          wrote on last edited by
          #4

          If the event is for an action internal to the user control , it is better to use javascript you can atleast avoid a post back. But if the event raised is to be notified to the page containing the user control only then is it worthwhile to consider adding a event to the user control and using it on the page and causing post back Think about it Thanks Srinivas

          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