I want to add the controls in a webform created in asp.net using
vb.net as the choosen language.if i add label control programmatically , at run time , it works properly ; bt if i try to add textbox or button controls then it shows the error on the page .
the code that i'm writing is:----
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim btn As New Label
btn.Text = "Click"
btn.ID = "Button1"
Me.Controls.Add(btn)
Dim t1 As New TextBox
Me.Controls.Add(t1)
End Sub
the error it shows is :---
Server Error in '/WebApplication8' Application.
--------------------------------------------------------------------------------
Control '_ctl0' of type 'TextBox' 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 '_ctl0' of type 'TextBox' must be placed inside a form tag with runat=server.