Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 February 4th, 2004, 04:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default Dynamically created controls

Does anyone know how to keep dynamically created controls to persist between postbacks. I am able to keep their values, but if I don't recreate them each time in the code-behind they don't show up.

I am sure it is something simple, but I am unable to find it. Thanks.

J
 
Old February 4th, 2004, 04:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

What does your Page_Load Sub look like?

 
Old February 4th, 2004, 05:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Right now it consists of building the table and adding rows, labels, etc. based upon the number entered into a text box. But I have to do this on every post back. I want to do it one time and then change the values in the labels on the next post back without having to recreate them.

If I don't recreate them on postback, they don't show up. I want them act to like the controls that are designed by the form designer or is this asking too much?

J
 
Old February 4th, 2004, 07:09 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

That's part of the problem with dynamic controls. They are truly dynamic. Unless you create them every time, they dissappear. There's no way around this aside from ensuring they are created every time.

When asp.net parses the aspx and ascx files, it instantiates all the controls it finds. So similarly, you would need to manually instantiate controls that are dynamic. Viewstate should be able to maintain their states and values and such (unless you reset those as well) but you need to make sure the control is there.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old February 4th, 2004, 09:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

That's what I thought but I was hoping to hear otherwise. Yeah, I don't have any problem with their viewstate. Thanks for the information.

J





Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me about dynamically created controls vingo_mail ASP.NET 2.0 Basics 1 March 24th, 2008 12:54 PM
Problems with Dynamically created controls Preeti_Singh .NET Framework 1.x 1 March 7th, 2007 01:30 PM
Correctly disposing dynamically created controls simarik C# 2 December 20th, 2005 08:49 PM
Events for multiple dynamically created controls Puck312 Pro VB 6 5 August 29th, 2005 03:05 PM





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