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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. image button click event

image button click event

Scheduled Pinned Locked Moved ASP.NET
questionhelptutorial
3 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.
  • H Offline
    H Offline
    harithadotnet
    wrote on last edited by
    #1

    In code behind i have created image button control and placed in placeholder dynamically. can anyone help me how to add image button click event code is as follows ImageButton img; for (int i = 1; i < 11; i++) { img = new ImageButton(); img.ID = "img" +i.ToString(); img.ImageUrl="pg/1212/"+ i +".jpg"; ()"; pl.Controls.Add(img); (pl is place holder control id) what is the code to add image control click event ? plz let me know if u know the ans. Thanks in advance. Haritha

    Haritha

    S C 2 Replies Last reply
    0
    • H harithadotnet

      In code behind i have created image button control and placed in placeholder dynamically. can anyone help me how to add image button click event code is as follows ImageButton img; for (int i = 1; i < 11; i++) { img = new ImageButton(); img.ID = "img" +i.ToString(); img.ImageUrl="pg/1212/"+ i +".jpg"; ()"; pl.Controls.Add(img); (pl is place holder control id) what is the code to add image control click event ? plz let me know if u know the ans. Thanks in advance. Haritha

      Haritha

      S Offline
      S Offline
      Sherin Iranimose
      wrote on last edited by
      #2

      Hi try this img.Click += new System.EventHandler(this.MyClick); MyClick is user defined function. protected void MyClick(object sender, EventArgs e) { //Your code will go here.... }


      To succeed, we must first believe that we can. Sherin Iranimose


      1 Reply Last reply
      0
      • H harithadotnet

        In code behind i have created image button control and placed in placeholder dynamically. can anyone help me how to add image button click event code is as follows ImageButton img; for (int i = 1; i < 11; i++) { img = new ImageButton(); img.ID = "img" +i.ToString(); img.ImageUrl="pg/1212/"+ i +".jpg"; ()"; pl.Controls.Add(img); (pl is place holder control id) what is the code to add image control click event ? plz let me know if u know the ans. Thanks in advance. Haritha

        Haritha

        C Offline
        C Offline
        Chetan Ranpariya
        wrote on last edited by
        #3

        Hi, Create a method with 2 arugments. protected void img_Click ( object sender, ImageClickEventArgs e ) { ImageButton img = ( ImageButton )sender; Response.Write(img.ID + "
        "); } The above method will work as a handler for the click event of your dynamically generated imagebuttons. To assign this event handler to the event of imagebuttons modify your for loop as following. for (int i = 1; i < 11; i++) { img = new ImageButton(); img.ID = "img" +i.ToString(); img.ImageUrl="pg/1212/"+ i +".jpg"; img.Click += new ImageClickEventHandler( img_Click ); pl.Controls.Add(img); (pl is place holder control id) } I hope this will help you.

        Thanks and Regards, Chetan Ranpariya

        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