Runat = "server"

J

Jim Heavey

I have a Placeholder control. I add a Link Button in code to the place
holder. I set the "ID" value of the LinkButton. When I run, I get the
following error "Control 'lnkItem0' of type 'LinkButton' must be placed
inside a form tag with runat=server".

I do not see a property for "Runat", so I used the Attributes.Add method to
add the Runat="Server", but I get the exact same error. Here is the code..

LinkButton lnk1 = new LinkButton();
lnk1.ID = "lnkItem" + ctr.ToString();
lnk1.Text = "Edit";
lnk1.Attributes.Add("runat","Server");
// Add to the place holder control
plcDataEntry.Controls.Add(lnk1);
// add the event handler
lnk1.Click += new System.EventHandler(this.lnkEditProcesser_Click);

What do I need to do to clear this error?

Thanks in advance for your assistance!!!!!!!!!
 
P

Patrice Scribe

It means you must add this control as a child of the form control that has a
runat="server" attribute. For now the control is added after all controls.

Try rather something like :
- use an ID such as "frm" on your form tag
- use frm.Controls to add this control as a child of this control

Patrice
 
J

Jim Heavey

I'm confused.

If the control being added resides in a "PlaceHolder", don't I have to add
the control to the PlaceHolder and not the form? I presume that when I add
the Placeholder control to the form using the IDE, that it is added to the
Form Control collection. The placeholder has a "runat="server"".

The Placeholder control apparently is a control which can house other
controls, as you have a method which allows you to add new controls to it.


So is the problem that I have not propertly coded the portion which
specifies the "runat="Server"" or what?

I will try what you suggested, but it does not seem make sense to me if I
understand controls which house other controls....
 
G

Guest

Jim, also doublecheck that your placeholder is within the <form></form> in the html. What you're trying to do by adding a control to a placeholder already on the form should work fine (it's actually a very handy way to do all sorts of interesting things at run-time)

----- Jim Heavey wrote: ----

I'm confused

If the control being added resides in a "PlaceHolder", don't I have to add
the control to the PlaceHolder and not the form? I presume that when I add
the Placeholder control to the form using the IDE, that it is added to the
Form Control collection. The placeholder has a "runat="server""

The Placeholder control apparently is a control which can house other
controls, as you have a method which allows you to add new controls to it


So is the problem that I have not propertly coded the portion which
specifies the "runat="Server"" or what

I will try what you suggested, but it does not seem make sense to me if I
understand controls which house other controls...
 
P

Patrice

Sorry,

In this case I would check if the placeholder control is itself within the
form tag. All controls should be directlty or indirectly added as child of
the form tag.

Patrice
 

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

Top