473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Placing controls dynamically on web form

Hi,

I need to find a way to place multiple textboxes and other controls
dynamically on a web form, I tried to put a placeholder on a form then
create and add controls dynamically into the place holder. It is not
working, all controls added disappear after the postback.

I tried to find a working sample on Internet with no lucks, some samples are
able to keep the controls after the postback, but all values entered before
the postback are lost.
TIA
Jul 7 '07 #1
2 2097
Hi,

If viewstate is on, do you have something wrong with this simple code?

protected void Page_Init(object sender, EventArgs e)
{
TextBox t1 = new TextBox();
t1.ID = "textBox1";
form1.Controls.Add(t1);
.....

Anyway, have you read it: http://aspnet.4guysfromrolla.com/articles/092904-1.aspx

Alex
http://devkids.blogspot.com
Hi,

I need to find a way to place multiple textboxes and other controls
dynamically on a web form, I tried to put a placeholder on a form
then create and add controls dynamically into the place holder. It is
not working, all controls added disappear after the postback.

I tried to find a working sample on Internet with no lucks, some
samples are able to keep the controls after the postback, but all
values entered before the postback are lost.

TIA


Jul 7 '07 #2
"Raymond Du" <rd**@yahoo.comwrote in message
news:Oj*************@TK2MSFTNGP06.phx.gbl...
I need to find a way to place multiple textboxes and other controls
dynamically on a web form, I tried to put a placeholder on a form then
create and add controls dynamically into the place holder. It is not
working, all controls added disappear after the postback.
If you don't want them to dissappear during pstback, you have to create
them again on every postback. Contrary to the properties of existing
controls, which are preserved during postback in the ViewState, the fact
that you created new controls is not preserved at all in the ViewState.
You typically add the controls in the Page_Init event, and you don NOT
use a !Page.IsPostBack, that is, you re-create the controls on every
postback. If you do it this way, the values introduced in the controls
before the PostBack can be read in the Page_Load event, because asp.net
recovers them internally during the LoadViewState and LoadPostbackData
events that occur between Init and Load.

See this article:
http://www.codeproject.com/useritems/lifecycle.asp
Jul 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
7
by: Grant | last post by:
I have this table on my form which gets populated with data from my database at runtime. I would like to place some controls (linkbutton, textbox etc.) beneath the table when it is complete - at...
7
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the...
4
by: Stu | last post by:
Hi, I am writing a content management system that has to have W3C compliant output. The pages are template driven and there are special strings within the template to be used as placeholders for...
2
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to...
6
by: dhnriverside | last post by:
Hi peeps, I'm trying to create some controls textboxes at runtime, based on the number of items in a IETreeView that are checked. That I can do, I've got a place holder and I can create the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.