How do I fix this error....

K

Kevin

I created a button in the design window and placed some code in the
Button_Click event. When I run the program and click the button, I
get this error message:

Control 'Button1' of type 'Button' must be placed inside a form tag
with runat=server.

I've tried searching Microsoft's web site and there's nothing on this
error.
 
K

Kevin Spencer

The error message says it all. You must place the Control inside a form tag
with runat=server; in other words, inside a WebForm.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
G

George Ter-Saakov

Easy.
Just read the message and do what you've been told.
Add <form runat=server name="name1"> ... </form> to the page
So the Button is inside of the form tag.

George.
 
K

Kevin

OK, just a silly question--why isn't the code added to the HTML when I
create the button in the Design screen? Is this a bug in the IDE or
is it this way on purpose to aggrivate us newbies?
 
K

Kevin

Looking at the HTML for my Web Form, the button IS there in between
the <form></form> tags.

Am I missing something here?
 
B

Brandon Potter

Kevin,

I would suggest creating a new web form by right clicking the name of your
project in solution explorer, and selecting Add > New Web Form, and take a
look at the HTML that is generated by the designer when a form is first
created, compare it with the web form that contains the error, and you
should see what is meant by the error (most ASP.NET controls that are
accessed programmatically are runat=server).

(And you are using VS.NET 2003, correct?)

Brandon
 
G

George Ter-Saakov

Probably 99% of the people would agree with my statement.

"The less VS fix HTML for me the better it is."

So i guess you are just form that 1% :)

George.
 
G

George Ter-Saakov

You are not listening.

"You must place the Control inside a form tag with runat=server; in other
words, inside a WebForm"


Do you have runat=server in a form tag????

George.
 
K

Kevin

I figured it out. It was just that one WebForm that didn't have the
<form></form> tags.

I've been programming in VB6 for a few years. I'm new to web
programming in general, so sorry if my questions seem stupid to you.
 
K

Kevin Spencer

If it's any consolation, Kevin, many programmers regard ASP.Net as one of
the most difficult programming technologies to work with. Not so much due to
the design of the platform, but because of the stateless HTTP environment,
which necessitates some complicated work-arounds to handle state management.
Hang in there!

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

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