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. Advertising

  2. Chakravarti Mukesh

    MattC Guest

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

    MattC
    "Chakravarti Mukesh" <> wrote in message
    news:%...
    > 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
    >
    MattC, Jan 10, 2006
    #2
    1. Advertising

  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

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "MattC" <> wrote in message
    news:%...
    > Try placing a placeholder control on the page and adding your controls to
    > that.
    >
    > MattC
    > "Chakravarti Mukesh" <> wrote in message
    > news:%...
    >> 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
    >>

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

    brijesh patel

    Joined:
    Feb 14, 2013
    Messages:
    1
    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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RCBTaGVsZG9u?=

    Adding validation controls programmatically

    =?Utf-8?B?RCBTaGVsZG9u?=, May 11, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,771
    =?Utf-8?B?RCBTaGVsZG9u?=
    May 11, 2004
  2. Tim Marsden

    Adding controls programmatically.

    Tim Marsden, May 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    572
    Steven Cheng[MSFT]
    May 25, 2004
  3. Replies:
    0
    Views:
    489
  4. Rob Meade
    Replies:
    3
    Views:
    435
    Alexey Smirnov
    May 15, 2007
  5. Replies:
    4
    Views:
    518
Loading...

Share This Page