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

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

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.
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:
    6,164
    =?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:
    795
    Steven Cheng[MSFT]
    May 25, 2004
  3. Replies:
    0
    Views:
    649
  4. Rob Meade
    Replies:
    3
    Views:
    618
    Alexey Smirnov
    May 15, 2007
  5. Replies:
    4
    Views:
    784
  6. D Sheldon

    Adding validation controls programmatically

    D Sheldon, May 11, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    325
    D Sheldon
    May 11, 2004
  7. Adding Controls to a Web Forms Page Programmatically

    , Mar 17, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    299
  8. Jason Dunbar

    Programmatically Adding Web User Controls

    Jason Dunbar, Nov 8, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    243
    Jason Dunbar
    Nov 8, 2004
Loading...