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. How we can create image button control dynamically ?

How we can create image button control dynamically ?

Scheduled Pinned Locked Moved ASP.NET
question
9 Posts 4 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.
  • M Offline
    M Offline
    Masood Kochi SSF
    wrote on last edited by
    #1

    How we can create image button control dynamically ?

    C I C 3 Replies Last reply
    0
    • M Masood Kochi SSF

      How we can create image button control dynamically ?

      C Offline
      C Offline
      Christian Flutcher
      wrote on last edited by
      #2

      ImageButton button = new ImageButton();
      button.Id = "something";

      add this button to a panel or place holder.

      1 Reply Last reply
      0
      • M Masood Kochi SSF

        How we can create image button control dynamically ?

        I Offline
        I Offline
        Imran Khan Pathan
        wrote on last edited by
        #3

        Masood Kochi,SSF wrote:

        How we can create image button control dynamically ?

        Create object of ImageButton,Set require properties and add in the page for example ImageButton imgBtn=new ImageButton(); imgBtn.ID="imgBtn"; imgBtn.ImageUrl="imagePath"; //Add image button in page.Suppose You have put one panel control on the page and ID is pnl pnl.Controls.Add(imgBtn);

        please don't forget to vote on the post that helped you.

        M 1 Reply Last reply
        0
        • M Masood Kochi SSF

          How we can create image button control dynamically ?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          This is trivial, the hard part is capturing viewstate from this control ( won't happen if you create it in page load, or later )

          Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

          1 Reply Last reply
          0
          • I Imran Khan Pathan

            Masood Kochi,SSF wrote:

            How we can create image button control dynamically ?

            Create object of ImageButton,Set require properties and add in the page for example ImageButton imgBtn=new ImageButton(); imgBtn.ID="imgBtn"; imgBtn.ImageUrl="imagePath"; //Add image button in page.Suppose You have put one panel control on the page and ID is pnl pnl.Controls.Add(imgBtn);

            please don't forget to vote on the post that helped you.

            M Offline
            M Offline
            Masood Kochi SSF
            wrote on last edited by
            #5

            Ok ..Thanks but How wecan raise click event on that image button

            I 1 Reply Last reply
            0
            • M Masood Kochi SSF

              Ok ..Thanks but How wecan raise click event on that image button

              I Offline
              I Offline
              Imran Khan Pathan
              wrote on last edited by
              #6

              Masood Kochi,SSF wrote:

              but How wecan raise click event on that image button

              Write this line to create Event

              imgBtn.Click += new ImageClickEventHandler(imgBtn_Click);

              This is event of Image Button

              public void imgBtn_Click(object sender, ImageClickEventArgs e)
              {
              //Write your code here
              }

              please don't forget to vote on the post that helped you.

              C 1 Reply Last reply
              0
              • I Imran Khan Pathan

                Masood Kochi,SSF wrote:

                but How wecan raise click event on that image button

                Write this line to create Event

                imgBtn.Click += new ImageClickEventHandler(imgBtn_Click);

                This is event of Image Button

                public void imgBtn_Click(object sender, ImageClickEventArgs e)
                {
                //Write your code here
                }

                please don't forget to vote on the post that helped you.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                May not work - unless the button is created early enough, it won't exist when the viewstate tree is restored.

                Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

                I 1 Reply Last reply
                0
                • C Christian Graus

                  May not work - unless the button is created early enough, it won't exist when the viewstate tree is restored.

                  Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

                  I Offline
                  I Offline
                  Imran Khan Pathan
                  wrote on last edited by
                  #8

                  Christian Graus wrote:

                  May not work

                  It'll work on page load event also.I worked on it many times

                  please don't forget to vote on the post that helped you.

                  C 1 Reply Last reply
                  0
                  • I Imran Khan Pathan

                    Christian Graus wrote:

                    May not work

                    It'll work on page load event also.I worked on it many times

                    please don't forget to vote on the post that helped you.

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    Really ? Are you using .NET 3.5 ? I am using 2.0 and have found problems with this, I've also done it many times, but I had to create my controls in the loadviewstate event.

                    Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

                    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