Adding Controls Programmatically

Discussion in 'ASP .Net' started by Chakravarti Mukesh, Jan 10, 2006.

  1. Hi All,
    I tried to add controls on page (C#) by using
    Page.Controls.Add(ctrl);
    it displays me an error

    Server Error in '/AgentExtension' Application.
    --------------------------------------------------------------------------------

    Control 'ctl02' of type 'ImageButton' must be placed inside a form tag with
    runat=server.
    How this could be done?

    Thanks
     
    Chakravarti Mukesh, Jan 10, 2006
    #1
    1. Advertisements

  2. Chakravarti Mukesh

    MattC Guest

    Try placing a placeholder control on the page and adding your controls to
    that.

    MattC
     
    MattC, Jan 10, 2006
    #2
    1. Advertisements

  3. Chakravarti Mukesh

    Karl Seguin Guest

    Normally how I do it. You can also simply declare the form in codebehind
    and add it to that too.

    protected HtmlForm Form1;

    Form1.Controls.Add(...);

    Karl
     
    Karl Seguin, Jan 10, 2006
    #3
  4. Chakravarti Mukesh

    brijesh patel

    Joined:
    Feb 14, 2013
    Messages:
    1
    Likes Received:
    0
    ImageButton img = new ImageButton(); // to create the object of class first

    Page.Form.Controls.Add(img); //using this code you can add control on page
     
    brijesh patel, Feb 14, 2013
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.