Dynamic Text Box

kosj@hebeler.com

New member
Joined
Feb 24, 2009
Messages
3
Programming Experience
Beginner
Trying to get some help on retrieving what the user enters into a dynamic text box. The following does not work but this is how everyone says will work.
VB.NET:
                For intcount = 0 To snqty - 1
                     Dim Txtdynamic As TextBox
                    Txtdynamic.ID = "txtdynamic_" & intcount & "_mycntrl"
                    Txtdynamic = Me.FindControl("txtdynamic_"                  
                                        & intcount.ToString & "_mycntrl") 
                    MsgBox(Txtdynamic.Text)
                Next
I get a null reference error: Object reference not set to an instance of an object. Please help! This is driving me crazy! Thanks.
 
Last edited by a moderator:
I see a few things wrong with the code vs what you're trying to do.

First off the null reference error is because you never create an instance of Txtdynamic, but that doesn't matter since Textboxes don't have an ID property that you're trying to use and form's dont have a FindControl() method either, it does have a FindForm() method though.
 
using Visual Web Developer 2008 and creating a web site
You can't create Windows Forms applications with VWD, let's move this thread to the ASP.NET section of the forums.

JB is right about that you haven't created a TextBox, use the New operator to create Textbox instance and assign it to the Txtdynamic variable.

FindControl will not find it until you add it to the page, for example Form.controls.Add(Txtdynamic).
 
Back
Top