Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 13th, 2011, 08:52 PM
FOD FOD is offline
Authorized User
 
Join Date: May 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Accessing webform textbox.text from a loop

I'm trying to extract the text from 20 textboxes in a webform and place the information into my database using entity framework. The project builds fine but I keep getting a null error exception on the quicklistitems.Item = ((TextBox)FindControl("txtListItem" + i)).Text; line during testing. I'm not sure if this is the right track or if there is a better class/method to use for pulling data from web controls with loops. I would appreciate any help anyone may be able to provide.

for (int i = 1; i <= 20; i++)
{
var quicklistitems = new QuickListItem();
quicklistitems.ListID = quicklist.ID;
quicklistitems.Item = ((TextBox)FindControl("txtListItem" + i)).Text;
context.QuickListItems.AddObject(quicklistitems);
}
context.SaveChanges();

Thanks,
FOD
 
Old September 13th, 2011, 09:24 PM
FOD FOD is offline
Authorized User
 
Join Date: May 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default The answer was in the client side id

I figured it out, the problem was that I wasn't specifying the client side textbox id so it couldn't find the control. I guess sometimes just posting the question makes you think harder about the answer.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing previous item in current-group() in loop mikeymikey XSLT 1 January 4th, 2008 06:47 AM
Display current date and time in a webform TextBox cesemj ASP.NET 2.0 Basics 4 October 22nd, 2007 04:07 PM
Accessing text in a hyperlink field mvyjim ASP.NET 2.0 Professional 0 March 10th, 2007 05:22 PM
Accessing a Cell in a Webform Datagrid hexOffender VB.NET 2002/2003 Basics 1 December 28th, 2006 01:14 AM
Using loop to change text of multiple textboxes snowy0 VB.NET 6 July 29th, 2004 08:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.