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. ADD controls at runtime in webform

ADD controls at runtime in webform

Scheduled Pinned Locked Moved ASP.NET
helpsysadmin
5 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.
  • J Offline
    J Offline
    Jmshastri
    wrote on last edited by
    #1

    hello, I have tried to add controls at runtime with following code Dim obj As New TextBox obj.Text = "hi" Me.Controls.Add(obj) I got following Error: Control '_ctl0' of type 'TextBox' must be placed inside a form tag with runat=server. What should i do,please help me....

    M H 2 Replies Last reply
    0
    • J Jmshastri

      hello, I have tried to add controls at runtime with following code Dim obj As New TextBox obj.Text = "hi" Me.Controls.Add(obj) I got following Error: Control '_ctl0' of type 'TextBox' must be placed inside a form tag with runat=server. What should i do,please help me....

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

      Hi there, I guess you are adding the TextBox control to the Page instance. The TextBox is one of the controls requiring to be placed inside the tag Form with runat=server, so in this case you can access the Form element, then add the textBox to it. You can also simply place a container control like Panel, PlaceHolder ...inside the tag Form in the web page, then add the TextBox to the container.

      J 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, I guess you are adding the TextBox control to the Page instance. The TextBox is one of the controls requiring to be placed inside the tag Form with runat=server, so in this case you can access the Form element, then add the textBox to it. You can also simply place a container control like Panel, PlaceHolder ...inside the tag Form in the web page, then add the TextBox to the container.

        J Offline
        J Offline
        Jmshastri
        wrote on last edited by
        #3

        thanks it works,now i have to add at specified location what should i do?

        M 1 Reply Last reply
        0
        • J Jmshastri

          thanks it works,now i have to add at specified location what should i do?

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

          Jmshastri wrote:

          i have to add at specified location what should i do?

          The simple way is to place a container at that location, then add the textbox to the container. I wish I could give you more info when I'm not sure what you may want to do.

          1 Reply Last reply
          0
          • J Jmshastri

            hello, I have tried to add controls at runtime with following code Dim obj As New TextBox obj.Text = "hi" Me.Controls.Add(obj) I got following Error: Control '_ctl0' of type 'TextBox' must be placed inside a form tag with runat=server. What should i do,please help me....

            H Offline
            H Offline
            HimaBindu Vejella
            wrote on last edited by
            #5

            This is the code in C# private void Button1_Click(object sender, System.EventArgs e) { int n= Convert.ToInt32(DropDownList1.SelectedItem.Text); for(int i=0;i "Aim to go where U have never been B4 and Strive to achieve it" http://groups.yahoo.com/subscribe/dotnetforfreshres http://himabinduvejella.blogspot.com

            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