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. Adding CheckBox control at runtime

Adding CheckBox control at runtime

Scheduled Pinned Locked Moved ASP.NET
csharphelpjavascriptasp-nettutorial
5 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.
  • P Offline
    P Offline
    psmukil
    wrote on last edited by
    #1

    How to add a checkbox control at runtime in a Panel using placeholder or wihtout using ph. I have added the control, but controls are added on the same location i think. So its showing a single control. Is it possible to do it in the Javascript function.so that there will be no page rendering. Wherein in a windows application we can specify the location.Im using ASP.Net 2.0 and C# as code behind. Plese help me to solve this problem. Thanks in advance. Its a urgent requirement. Help me out. Regards Mukil.

    R 1 Reply Last reply
    0
    • P psmukil

      How to add a checkbox control at runtime in a Panel using placeholder or wihtout using ph. I have added the control, but controls are added on the same location i think. So its showing a single control. Is it possible to do it in the Javascript function.so that there will be no page rendering. Wherein in a windows application we can specify the location.Im using ASP.Net 2.0 and C# as code behind. Plese help me to solve this problem. Thanks in advance. Its a urgent requirement. Help me out. Regards Mukil.

      R Offline
      R Offline
      russellsoft
      wrote on last edited by
      #2

      You must put it at end of PageLoad... Because ViewState will refreshed after PageLoad event CheckBox chb = new CheckBox(); chb.ID = "someID"; pnl.Controls.Add(chb); pnl - is your Panel which you added in designer... It is simple or I didn't understand what is a problem in?..

      R 1 Reply Last reply
      0
      • R russellsoft

        You must put it at end of PageLoad... Because ViewState will refreshed after PageLoad event CheckBox chb = new CheckBox(); chb.ID = "someID"; pnl.Controls.Add(chb); pnl - is your Panel which you added in designer... It is simple or I didn't understand what is a problem in?..

        R Offline
        R Offline
        Ricardo Casquete
        wrote on last edited by
        #3

        Instead of the Page Load, sometimes I have had to add the Controls at runtime before the OnInit() Method ends. As Russel has said, if not, you will lose the ViewState and you won't be able to recover the value of the CheckBox. Remember to do a FindControl ( "CheckBoxID" ) in the PlaceHolder to get the CheckBox Ricardo Casquete

        P 1 Reply Last reply
        0
        • R Ricardo Casquete

          Instead of the Page Load, sometimes I have had to add the Controls at runtime before the OnInit() Method ends. As Russel has said, if not, you will lose the ViewState and you won't be able to recover the value of the CheckBox. Remember to do a FindControl ( "CheckBoxID" ) in the PlaceHolder to get the CheckBox Ricardo Casquete

          P Offline
          P Offline
          psmukil
          wrote on last edited by
          #4

          My problem is, In button click i need to add button as many as i want. But Once the control is adding, because as you said postback and page rendering. How to avoid this. Please help me out. The code is given below, I have tried with html table and adding rows and cells within rows. TextBox txtName = new TextBox(); txtName.ID = "txtName"; txtName.Visible = true; txtName.Width = 150; txtName.Text = "Check"; PHItem.Controls.Add(txtName); Using Table: HtmlTableRow htrow = new HtmlTableRow(); HtmlTableCell htcell = new HtmlTableCell(); TextBox txtName = new TextBox(); txtName.ID = "txtName"; txtName.Visible = true; txtName.Width = 150; txtName.Text = "Check"; htcell.Controls.Add(txtName); htrow.Cells.Add(htcell);

          I 1 Reply Last reply
          0
          • P psmukil

            My problem is, In button click i need to add button as many as i want. But Once the control is adding, because as you said postback and page rendering. How to avoid this. Please help me out. The code is given below, I have tried with html table and adding rows and cells within rows. TextBox txtName = new TextBox(); txtName.ID = "txtName"; txtName.Visible = true; txtName.Width = 150; txtName.Text = "Check"; PHItem.Controls.Add(txtName); Using Table: HtmlTableRow htrow = new HtmlTableRow(); HtmlTableCell htcell = new HtmlTableCell(); TextBox txtName = new TextBox(); txtName.ID = "txtName"; txtName.Visible = true; txtName.Width = 150; txtName.Text = "Check"; htcell.Controls.Add(txtName); htrow.Cells.Add(htcell);

            I Offline
            I Offline
            Ista
            wrote on last edited by
            #5

            I would create a class used to capture the rows or buttons. Just create arrays or properties with the class mark it as [Serializable] and save it to the view at the end of page load or when ever you add them Then on post back on the PageLoad event recreate the tables or buttons based on what you saved in the view state. 1 line of code equals many bugs. So don't write any!!

            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