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. dynamically add control

dynamically add control

Scheduled Pinned Locked Moved ASP.NET
helpdesignsysadmin
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.
  • R Offline
    R Offline
    rajmani
    wrote on last edited by
    #1

    hi all, I have create one ascx file,then i called my aspx form in Programmatically this is the code **Dim c1 As Control = LoadControl("Web.ascx") Page.Controls.Add(c1),**Problem is i want add linkbutton, Dim link As System.Web.UI.WebControls.LinkButton link = c1.FindControl("linkbutton") but error showing, this is the error Control '_ctl0_LinkButton1' of type 'LinkButton' must be placed inside a form tag with runat=server. cheers

    M M 2 Replies Last reply
    0
    • R rajmani

      hi all, I have create one ascx file,then i called my aspx form in Programmatically this is the code **Dim c1 As Control = LoadControl("Web.ascx") Page.Controls.Add(c1),**Problem is i want add linkbutton, Dim link As System.Web.UI.WebControls.LinkButton link = c1.FindControl("linkbutton") but error showing, this is the error Control '_ctl0_LinkButton1' of type 'LinkButton' must be placed inside a form tag with runat=server. cheers

      M Offline
      M Offline
      Mircea Grelus
      wrote on last edited by
      #2

      When adding controls dinamically to a page, you should add them inside a placeholder control. This assures that your controls will render correctly. Sometimes when not adding the controls in the place holder they will work other times they won't. Just like in your case. So, add a place holder control in the page controls collection, then add your linkbutton inside the place holder. regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

      1 Reply Last reply
      0
      • R rajmani

        hi all, I have create one ascx file,then i called my aspx form in Programmatically this is the code **Dim c1 As Control = LoadControl("Web.ascx") Page.Controls.Add(c1),**Problem is i want add linkbutton, Dim link As System.Web.UI.WebControls.LinkButton link = c1.FindControl("linkbutton") but error showing, this is the error Control '_ctl0_LinkButton1' of type 'LinkButton' must be placed inside a form tag with runat=server. cheers

        M Offline
        M Offline
        minhpc_bk
        wrote on last edited by
        #3

        Because you add the dynamic control to the Controls collection of the Page instance, so it is placed outside the form element which is a child of the parent Page. So like Mircea suggested, you simply place a container like PlaceHolder control onto the web page inside in the form element, and add the dynamic control to the container.

        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