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. Dynamic Event Handler

Dynamic Event Handler

Scheduled Pinned Locked Moved C#
databasewpfwcfcomhelp
2 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.
  • P Offline
    P Offline
    pssuresh
    wrote on last edited by
    #1

    Menu Item names are directly coming from the database and i want to attach menu item with the event handler names. so i name event handler as "handle" + item.name(value from database) + "click".I want to attach it dynamically. the code is as follows //sample code public class myclass { protected void Handle_FileMenuItem_Click(System.Object sender, System.EventArgs e) { } public bindeventhandler() { string dynamiceventhandler=""; dynamiceventhandler="Handle_" + item.Name + "_Click"; Delegate temp=Delegate.CreateDelegate(typeof(EventHandler),this,dynamiceventhandler); item.Click+=(EventHandler)temp; } } The code is throwing error. Error binding to target method. Can anyone pl explain how to solve this error... i got the idea from this url http://www.dotnet247.com/247reference/msgs/21/106638.aspx

    S 1 Reply Last reply
    0
    • P pssuresh

      Menu Item names are directly coming from the database and i want to attach menu item with the event handler names. so i name event handler as "handle" + item.name(value from database) + "click".I want to attach it dynamically. the code is as follows //sample code public class myclass { protected void Handle_FileMenuItem_Click(System.Object sender, System.EventArgs e) { } public bindeventhandler() { string dynamiceventhandler=""; dynamiceventhandler="Handle_" + item.Name + "_Click"; Delegate temp=Delegate.CreateDelegate(typeof(EventHandler),this,dynamiceventhandler); item.Click+=(EventHandler)temp; } } The code is throwing error. Error binding to target method. Can anyone pl explain how to solve this error... i got the idea from this url http://www.dotnet247.com/247reference/msgs/21/106638.aspx

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi, I tried your provided code and it works just fine. Did you verified that the value of item.Name is e.g. FileMenuItem? Do you have a target method for all items that wil be binded ? Regards Sebastian

      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