By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,581 Members | 972 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,581 IT Pros & Developers. It's quick & easy.

Dynamically added controls and postback

P: n/a
I have a situation where I have to dynamically add controls at runtime.
I am not sure how to deal with postback and retaining values in
textboxes. I have seen examples where you have to include properties
with the same name in the C# codebehind class. But this defeats the use
of dynamic controls. Is there anyway to access and maintain the values
in the fields?
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Matthew:

I'm currently working on a project that needs to do the same thing you're describing. I had a lot of trouble finding good information on the topic, but after a lot of googling and even more trial/error, what I did was as follows:

- Create an HTML table on my form, gave it an ID and set runat="server"

- Wrote some functions that handle the layout. Basically what I did was to have the functions create new controls, append the controls to new HtmlTableCells, append the cells to new HtmlTableRows and then append the rows to the table on my form.

- Place a call to the layout functions in my page's OnInit. This, from what I was able to gather on various posts I found is critical.

- On postback, I get a reference to my form's table, then use FindControl(ControlName) to grab each control and get it's value and process as needed.

I've had no problems with this approach. I'm sure there are better (easier?) ways to handle this, but this method seems to be working out fine for the time being. If this needs any clarification, respond and I'll see what I can do.

----- Matthew Smith wrote: -----

I have a situation where I have to dynamically add controls at runtime.
I am not sure how to deal with postback and retaining values in
textboxes. I have seen examples where you have to include properties
with the same name in the C# codebehind class. But this defeats the use
of dynamic controls. Is there anyway to access and maintain the values
in the fields?

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.