Run-time error: <Control Name> must be placed inside a form tag with runat=server

M

Matthew Louden

It happend to me more than once. When I create web controls or move the
positions in VS.NET, I encountered the following run-time errors: It doesn't
matter what controls I create, the following 'checkbox' control is just an
example.


Control 'CheckBox1' of type 'CheckBox' must be placed inside a form tag with
runat=server.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control 'CheckBox1' of type
'CheckBox' must be placed inside a form tag with runat=server.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.


I know it's very easy to solve the problem, we simply move the code inside
the form block as follows:

<form id="Form1" method="post" runat="server">
'UI code
</form>

Maybe it's bug in VS.NET. I just want to see if anyone encountered similar
problem before.

Please advise. Thanks!
 
J

Jim Heavey

All asp.net controls (i.e "<asp:') where the Runat=Server
must be within the form tag ( and I would guess even
those ASP controls which are not runat server, but not
absolutely sure about that) those asp.n and the form tag
must be runat=server as well.
 
T

Teemu Keiski

It's not a bug, it's a very much designed feature. Certain controls need to
exist inside a server form for them to work properly.
 
L

Lloyd Sheen

I know what you mean. I have had more IDE related problems with things like
this. Everything is ok , move a control and then things are wrong. I think
the IDE is about where VB2 was. Still not totally ready for prime time.

I keep losing toolbar buttons etc. and it is very frustrating.
 
T

Teemu Keiski

Or with second reading, if the problem is that IDE moves them out of the
form, then it could be a bug. :)
 
Joined
Aug 30, 2006
Messages
2
Reaction score
0
Refer to the below articles that may help solve this problem.

GridView Export to Excel Problems
http://geekswithblogs.net/azamsharp/archive/2005/07/25/48213.aspx

Export GridView to Excel Complete Code
http://geekswithblogs.net/azamsharp/archive/2005/12/21/63843.aspx

This is reported as a bug by MS
http://lab.msdn.microsoft.com/Produ...edbackid=e4e08db1-8788-4e58-9e1f-daba86195d9f

The below code is required to add to avoid this error.
Code:
 [font=Verdana][size=2][font=Verdana][size=2][font=Courier New][color=#000000][font=Courier New] [/font][/color][color=#0000ff][font=Courier New]public override void [/font][/color][color=#000000][font=Courier New]VerifyRenderingInServerForm(Control control)
 	{
 	   [/font][/color][color=#008000][font=Courier New]// Confirms that an HtmlForm control is rendered for the
 [/font][/color][/font][/size][/font][/size][/font][font=Verdana][size=2][font=Verdana][size=2][font=Courier New][color=#008000][font=Courier New]	   // specified ASP.NET server control at run time.[/font][/color][/font][/size][/font][/size][/font]
 [font=Verdana][size=2][font=Verdana][size=2][font=Courier New][color=#008000][font=Courier New]	   // No code required here.[/font][/color][/font][/size][/font][/size][/font][font=Verdana][size=2][font=Verdana][size=2][font=Courier New][color=#000000][font=Courier New][/font][/color][/font][/size][/font][/size][/font]
 [font=Verdana][size=2][font=Verdana][size=2][font=Courier New][color=#008000][font=Courier New][/font][/color][color=#000000][font=Courier New]	}[/font][/color][/font][/size][/font][/size][/font]
 
Joined
Oct 12, 2006
Messages
1
Reaction score
0
System.Web.HttpException: Control of type 'GridView' must be placed inside a form ta

Even I am also getting the same exception.
But my Gridview control named 'GridView2' is inside the form tag with runat=server.

What can be the problem?









Matthew Louden said:
It happend to me more than once. When I create web controls or move the
positions in VS.NET, I encountered the following run-time errors: It doesn't
matter what controls I create, the following 'checkbox' control is just an
example.


Control 'CheckBox1' of type 'CheckBox' must be placed inside a form tag with
runat=server.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control 'CheckBox1' of type
'CheckBox' must be placed inside a form tag with runat=server.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.


I know it's very easy to solve the problem, we simply move the code inside
the form block as follows:

<form id="Form1" method="post" runat="server">
'UI code
</form>

Maybe it's bug in VS.NET. I just want to see if anyone encountered similar
problem before.

Please advise. Thanks!
 

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