How can I add a textbox into the form by using vb.net code for my web application?
I write the following code but the textbox didn't appear:
Dim newTxt As TextBox = New TextBox()
newTxt.Wrap = True
newTxt.Text = "Hello"
Me.Controls.Add(newTxt)
Printable View
How can I add a textbox into the form by using vb.net code for my web application?
I write the following code but the textbox didn't appear:
Dim newTxt As TextBox = New TextBox()
newTxt.Wrap = True
newTxt.Text = "Hello"
Me.Controls.Add(newTxt)
You are not adding your textbox to your form but rather to the page. First get the form object by using FindControl method:
VB Code:
Dim frm As Control Dim newTxt As TextBox = New TextBox() frm = Me.FindControl("FormIdHere") If frm Is Not Nothing '......your code for creating your textbox newTxt.Wrap = True newTxt.Text = "Hello" frm.Controls.Add(newTxt) End