Adding Controls Programmatically

C

Chakravarti Mukesh

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
 
M

MattC

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

MattC
 
K

Karl Seguin

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
 
Joined
Feb 14, 2013
Messages
1
Reaction score
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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top