Results 1 to 2 of 2

Thread: Add textbox using code

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    7

    Add textbox using code

    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)

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    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:
    1. Dim frm As Control
    2. Dim newTxt As TextBox = New TextBox()
    3.  
    4.  
    5. frm = Me.FindControl("FormIdHere")
    6.  
    7. If frm Is Not Nothing
    8.     '......your code for creating your textbox
    9.     newTxt.Wrap = True
    10.     newTxt.Text = "Hello"
    11.     frm.Controls.Add(newTxt)
    12. End

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width