Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old August 12th, 2011, 02:07 PM
Registered User
Points: 33, Level: 1
Points: 33, Level: 1 Points: 33, Level: 1 Points: 33, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic TextBox

I have created dynamic textbox now i want to insert data from created textbox, i am googling but didnt get solution that can work for me.

Table table = new Table();
table.ID = "Table1";
foreach (DataRow datarow in ds.Tables[0].Rows)

TableRow row = new TableRow();
TableCell cell = new TableCell();
TextBox txt= new TextBox();

txt.ID = "txt_" + datarow["subject_name"].ToString() + "_examdate";
TextBox TextBox1 = new TextBox();
txt.ID = "txt_" + datarow["subject_name"].ToString() + "_starttime";






protected void Button1_Click(object sender, EventArgs e)


public void IterateControls(Control parent)
TextBox txt_Mathematics_starttime = (TextBox)this.Page.FindControl("txt_Mathematics_st arttime");

txt_examtype.Text = txt_Mathematics_starttime.Text;

any help would be appreciated
Reply With Quote
  #2 (permalink)  
Old August 19th, 2011, 09:49 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

The problem with this approach is the way that web forms deals with the controls in the page structure. When you create new controls and add them to the page, you must do so reliably on every page cycle. ASP.NET constructs the page control tree from what it finds explicitly defined in the markup and from whatever is added programmatically up to the point the code in question is running. So the controls you put onto a page during one page cycle will not be there automatically on the next cycle unless you explicitly put them there, so the code that looks for the controls won't find anything.

The way this is typically handled is that you put your control generation code in the page load such that it always runs (i.e. no branching for IsPostback). That way, you reconstruct the control structure before event handling takes place. That being said, you may still run into problems with proper restoration of view state which I think is restored prior to page load (it's been a while since I dealt with web forms). This could have adverse effects regarding event firing when control change events are analyzed. This happens because dynamically created controls will have one value when created by code (e.g. a blank text box) but not have their state restored to preserve the value from the last page draw, then a "new" value gets written to the control from the form post action causing an event to fire when it shouldn't.

Working with dynamically generated controls in web forms is very tricky.
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic TextBox Name from Form Janie Excel VBA 1 March 24th, 2011 09:16 PM
dynamic textbox creation badamsreekar ASP.NET 2.0 Professional 1 July 26th, 2007 10:40 AM
Dynamic Textbox viprsh81 ASP.NET 2.0 Professional 2 July 20th, 2006 04:46 AM
How to assign dynamic value to textbox in struts JasmineStanly JSP Basics 0 August 22nd, 2005 03:56 AM
Dynamic TextBox stu9820 ASP.NET 1.0 and 1.1 Basics 2 February 4th, 2004 03:35 PM

All times are GMT -4. The time now is 08:21 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.