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. General Programming
  3. C#
  4. acessing an id from object sender

acessing an id from object sender

Scheduled Pinned Locked Moved C#
csharpasp-netquestion
3 Posts 2 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.
  • B Offline
    B Offline
    brsecu
    wrote on last edited by
    #1

    I've created buttons automatically based on rows of information. When someone pushes the button I call the eventhandler button1_Click(object sender, EventArgs e). Is there anyway to tell what the name of the button is? I'm using c# in asp.net. When debugging i can see the clientid but cant get it from sender.

    E 1 Reply Last reply
    0
    • B brsecu

      I've created buttons automatically based on rows of information. When someone pushes the button I call the eventhandler button1_Click(object sender, EventArgs e). Is there anyway to tell what the name of the button is? I'm using c# in asp.net. When debugging i can see the clientid but cant get it from sender.

      E Offline
      E Offline
      Edmundisme
      wrote on last edited by
      #2

      Cast the sender object to a Button:

      Button myButton = sender as Button;
      if(myButton != null)
      {
      string name = myButton.Name;
      }

      B 1 Reply Last reply
      0
      • E Edmundisme

        Cast the sender object to a Button:

        Button myButton = sender as Button;
        if(myButton != null)
        {
        string name = myButton.Name;
        }

        B Offline
        B Offline
        brsecu
        wrote on last edited by
        #3

        That did it thanks. Since im using asp i used myButton.id instead of name. Thanks again.

        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