By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

vb.net create button question

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"BrianDH" wrote:
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

Nov 21 '05 #2

P: n/a
Yes all tags are there. I never change or alter the ASP code.

"..:: Kevin ::.." wrote:
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

"BrianDH" wrote:
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

Nov 21 '05 #3

P: n/a
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

"BrianDH" wrote:
Yes all tags are there. I never change or alter the ASP code.

"..:: Kevin ::.." wrote:
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

"BrianDH" wrote:
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

Nov 21 '05 #4

P: n/a
Brian,

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

Cor
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.