![]() |
Problem using dynamically created textboxes
I am making a webform that allows the user to add another textbox by
clicking a button to allow them to enter however many names they need. The procedure that does this uses information entered in the currently existing textboxes. This works fine the first time they click the button, since the first textbox is hardcoded. However, the second time they click the button I recieve an error saying: [NullReferenceException: Object reference not set to an instance of an object.] PAPresenters.register.btnAddName_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\PAPresenters\register.aspx.vb:1 28 System.Web.UI.WebControls.Button.OnClick(EventArgs e) System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) System.Web.UI.Page.ProcessRequestMain() When I do a view source on the page, it gave the generated textboxes the ID that I told it to. I think the problem has something to do with ASP.NET forgetting the new controls when it looks for them the second time or something. The line of code where I recieve the error is: Line 126: 'Make sure there are no empty name fields Line 127: For i As Integer = 0 To namecount Line 128: If CType(FindControl("txtFName" & CStr(i)), TextBox).Text = "" OrElse CType(FindControl("txtLName" & CStr(i)), TextBox).Text = "" Then Line 129: Exit Sub Line 130: End If Why is ASP.NET unable to find the dynamically created controls? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/ |
| All times are GMT. The time now is 01:39 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.