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. Add a button dinamically

Add a button dinamically

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netquestion
6 Posts 5 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
    overfreeze
    wrote on last edited by
    #1

    Is there any way of adding a button to a web page dinamically? Say, a button that when clicked creates another button in the page? I know this is possible in a Windows Form, but not sure about a ASP.NET page. Thanks in advance.

    _ S B V 4 Replies Last reply
    0
    • O overfreeze

      Is there any way of adding a button to a web page dinamically? Say, a button that when clicked creates another button in the page? I know this is possible in a Windows Form, but not sure about a ASP.NET page. Thanks in advance.

      _ Offline
      _ Offline
      _mubashir
      wrote on last edited by
      #2

      yes, you can actually have a panel and put the control in there at the run time thanks, Mubashir

      Every job is a self portrait of the person who did it.

      1 Reply Last reply
      0
      • O overfreeze

        Is there any way of adding a button to a web page dinamically? Say, a button that when clicked creates another button in the page? I know this is possible in a Windows Form, but not sure about a ASP.NET page. Thanks in advance.

        S Offline
        S Offline
        Spunky Coder
        wrote on last edited by
        #3

        //In the ButtonClick event of the first button load the newbutton protected void Button1_Click(object sender, EventArgs e) { loadnewbutton = new Button(); loadnewbutton.Text = "NewButton"; loadnewbutton.ID = "newButton"; loadnewbutton.Click += new System.EventHandler(this.loadnewbutton_Click); this.PlaceHolder1.Controls.Add(loadnewbutton); } protected void loadnewbutton_Click(object sender, EventArgs e) { Response.Write("HEllo"); }

        Koushik

        S 1 Reply Last reply
        0
        • S Spunky Coder

          //In the ButtonClick event of the first button load the newbutton protected void Button1_Click(object sender, EventArgs e) { loadnewbutton = new Button(); loadnewbutton.Text = "NewButton"; loadnewbutton.ID = "newButton"; loadnewbutton.Click += new System.EventHandler(this.loadnewbutton_Click); this.PlaceHolder1.Controls.Add(loadnewbutton); } protected void loadnewbutton_Click(object sender, EventArgs e) { Response.Write("HEllo"); }

          Koushik

          S Offline
          S Offline
          Spunky Coder
          wrote on last edited by
          #4

          //Declare the loadnewbutton first. //I mean as follows. System.Web.UI.WebControls loadnewbutton = new Button();

          Koushik

          1 Reply Last reply
          0
          • O overfreeze

            Is there any way of adding a button to a web page dinamically? Say, a button that when clicked creates another button in the page? I know this is possible in a Windows Form, but not sure about a ASP.NET page. Thanks in advance.

            B Offline
            B Offline
            badgrs
            wrote on last edited by
            #5

            Just create an instance of the control you want and add it to the Controls collection of another control (a Panel or Placeholder is usually best). If you want user controls you can use the CreateUserControl method of the Page object. Note however that dynamic controls aren't persisted accross postbacks, you have to manage that yourself or check this out: DynamicControlsPlaceholder.aspx

            1 Reply Last reply
            0
            • O overfreeze

              Is there any way of adding a button to a web page dinamically? Say, a button that when clicked creates another button in the page? I know this is possible in a Windows Form, but not sure about a ASP.NET page. Thanks in advance.

              V Offline
              V Offline
              Vasudevan Deepak Kumar
              wrote on last edited by
              #6

              Yes

              Vasudevan Deepak Kumar Personal Homepage Tech Gossips

              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