473,785 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2136
Hi,

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

protected void Page_Init(objec t 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.com wrote in message
news:Oj******** *****@TK2MSFTNG P06.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.IsPostBac k, 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 LoadPostbackDat a
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
3562
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) template. Briefly -------------------------------------------------------------------------------------------- I need to create dynamically some controls on the forms, and display these
7
2431
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 the moment the controls just stay where I place them and the table gets built on top of them. I have tried searching the net for a solution but being on dial up its excruciatingly slow and I havent yet found the answer. Please could someone point me...
7
3262
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 load one of several controls: private void btnCategory_Click(object sender, System.EventArgs e) { Control myControl = LoadControl(DropDownList1.SelectedItem.Text + ".ascx"); PlaceHolder1.Controls.Add(myControl);
8
4316
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 button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
1
3024
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 web page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g....
4
1822
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 the content. However, when I output the content to a literal (as shown below) the body and html tags are within the form tags. Is there any way to position the form tags within the dynamically generated text (ie to just after the opening body...
2
2913
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 avoid the problem by avoiding the table control or resorting to databound controls that better manage state for me. I hope to understand how to solve the problem by using the Table web control and sticking to the approach of building the table at run...
6
2238
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 corrent number of controls. The problem is that they appear next to each other. I want to create the controls with some wording to the left of them (again, dynamically generated). Normally id use <table> with two colums, one for the
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.