473,323 Members | 1,551 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,323 software developers and data experts.

add web control dynamically

I have a web page where I have dropdownlist box with autopostback set
to true. The box has 3 items: 1, 2, and 3. I also have a Placeholder
and a button. Each time the user change the value of the
dropdownlist, I create dynamically one or x text box. Here is my
code...

for (int i = 0; i < Convert.ToInt32(ddListsRpt.SelectedValue); i++)
{
TextBox txtbx = new TextBox();
txtbx.Visible = true;
this.Placeholder3.Controls.Add(new LiteralControl("test: "));
Placeholder3.Controls.Add(txtbx);
}

The user can enter any value in each created text box.

Here is the code for my button:

foreach (Control ctrl in PlaceHolder3.Controls)
{
if (ctrl.ToString() == "System.Web.UI.WebControls.TextBox")
{
Response.Write (((TextBox) ctrl).Text.ToString());
}
}

What is interesting is that, for instance, a text box is dynamically
created then I enter 123 and click on the button. On the postback,
the text box disappear but I want it to stay so I can display the
value of the text box. Can someone tell me why it disappear? Thanks.
Nov 18 '05 #1
1 1862
it disappears because you have to create the text box irrespective of the
IsPostBack.
I mean the text box should always be created when your combobox particular
value is selected.
dynamically creating controls is equavalent to general ASP code. when posted
back, in ASP, all controls need to be thrown back to client in HTML..its
similar to that.

Av.
"powerranger" <ta*****@yahoo.com> wrote in message
news:13**************************@posting.google.c om...
I have a web page where I have dropdownlist box with autopostback set
to true. The box has 3 items: 1, 2, and 3. I also have a Placeholder
and a button. Each time the user change the value of the
dropdownlist, I create dynamically one or x text box. Here is my
code...

for (int i = 0; i < Convert.ToInt32(ddListsRpt.SelectedValue); i++)
{
TextBox txtbx = new TextBox();
txtbx.Visible = true;
this.Placeholder3.Controls.Add(new LiteralControl("test: "));
Placeholder3.Controls.Add(txtbx);
}

The user can enter any value in each created text box.

Here is the code for my button:

foreach (Control ctrl in PlaceHolder3.Controls)
{
if (ctrl.ToString() == "System.Web.UI.WebControls.TextBox")
{
Response.Write (((TextBox) ctrl).Text.ToString());
}
}

What is interesting is that, for instance, a text box is dynamically
created then I enter 123 and click on the button. On the postback,
the text box disappear but I want it to stay so I can display the
value of the text box. Can someone tell me why it disappear? Thanks.

Nov 18 '05 #2

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

Similar topics

2
by: anand | last post by:
Hi all, I have created a custom control which displays Image using Graphics.. I am using this control in a different windows application. I am dynamically creating the control and putting that...
0
by: John Crowley | last post by:
I'm having an odd problem with viewstate and a dynamically created control inside a repeater template. Basically, I have a repeater setup like this in the aspx:
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
7
by: Sky | last post by:
What I have currently: I have a user control called mod_container.aspx that is basically two divs -- the top a toolbar, that expands/collapse the second div which can contain other...
3
by: Eric | last post by:
I have built a composite user web control that I want to create dynamically. The form will contain a variable number of these controls and as well some of the contents of the user web control...
2
by: buran | last post by:
Dear ASP.NET Programmers, I have a HTML table (running as server control with the control ID: tblInsertSP). The table has 16 rows with textboxes. Depending on the value of the ddlSPType, which...
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
7
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb --...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.