vb.net create button question

G

Guest

Hi
I would ask this questiopn on the NG ASP but it would be days before anyone
might respond.

I am using vb.net code behind to create buttons to add to a web form.
After the buttons are created I get this error:
((Control '_ctl0' of type 'Button' must be placed inside a form tag with
runat=server.))

My Code example:
Dim mybutton As Button
Dim i As Integer
For i = 0 To 9
mybutton = New Button
mybutton.BackColor = Drawing.Color.Blue
mybutton.Text = (i + 1).ToString
mybutton.Width = New Unit(35)
Me.Controls.Add(mybutton)
AddHandler mybutton.Click, AddressOf mybutton_Click
Me.Controls.Add(New LiteralControl("<BR>"))
Next

Thanks for any help
BrianDH
 
G

Guest

Brian,

In the visual studio IDE, if you switch to the HTML view of your page and
ensure the <form> tag is placed after <body> and </form> is placed just
before </body> tag.

Once you have done this, run the page again and hopefully your problem
should be solved.

Thanks

Kevin
 
G

Guest

Brian,

I am unsure as to what could be causing this problem. I normally run into
this problem if the HTML tag that declares the control (in this case
<asp:button...) does not sit inside the <form> and </form> tags.

I normally never touch the tags either but on some occasions visual studio
gets a bit confused and puts the button declaration outside the form tag.

My only other suggestion would be to make sure the form tag looks something
like this:

<form id="Form1" method="post" runat="server">

Hope this helps

Kevin
 
C

Cor Ligthert

Brian,

My answer had be the same as from Kevin, so maybe you can look again.
And otherwise show us that HTML part.

Cor
 

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