|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
vb.net create button questionI 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 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 Show quoteHide quote "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 Yes all tags are there. I never change or alter the ASP code.
Show quoteHide quote "..:: 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 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 Show quoteHide quote "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 Brian,
My answer had be the same as from Kevin, so maybe you can look again. And otherwise show us that HTML part. Cor |
|||||||||||||||||||||||