473,811 Members | 3,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamically adding textbox

81 New Member
Hi,
the below code is for dynamically adding textbox, but it will adding for same textbox only my requirement is how many times i click add button such times textbox will add
for ex: if i click 10 times add button 10 textboxs will add
Expand|Select|Wrap|Line Numbers
  1. Session["TextBoxCount"] = "3";
  2.  
  3.          for (int a = 0; a < int.Parse(Session["TextBoxCount"].ToString()); a++)
  4.          {
  5.              TableRow tr = new TableRow();
  6.              TableCell tc = new TableCell();
  7.              TextBox tb = new TextBox();
  8.  
  9.              tb.Attributes.Add("runat", "Server");
  10.              tb.EnableViewState = false;
  11.              tb.MaxLength = 128;
  12.              tb.ID = "TextBox" + a;
  13.  
  14.              tc.Controls.Add(tb);
  15.              tr.Cells.Add(tc);
  16.              ctrlTable.Rows.Add(tr);
Apr 22 '08 #1
2 1383
shweta123
692 Recognized Expert Contributor
Hi,

What error are you getting into this?



Hi,
the below code is for dynamically adding textbox, but it will adding for same textbox only my requirement is how many times i click add button such times textbox will add
for ex: if i click 10 times add button 10 textboxs will add
Session["TextBoxCou nt"] = "3";

for (int a = 0; a < int.Parse(Sessi on["TextBoxCou nt"].ToString()); a++)
{
TableRow tr = new TableRow();
TableCell tc = new TableCell();
TextBox tb = new TextBox();

tb.Attributes.A dd("runat", "Server");
tb.EnableViewSt ate = false;
tb.MaxLength = 128;
tb.ID = "TextBox" + a;

tc.Controls.Add (tb);
tr.Cells.Add(tc );
ctrlTable.Rows. Add(tr);
Apr 22 '08 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Are you getting any errors?
Have you seen this article on how to use dynamic controls in ASP.NET? It has an example on how to dynamically add Textboxes to your web pages.

-Frinny
Apr 22 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1267
by: LU | last post by:
I have code to dynamically add more text boxes when the user clicks the 'add another carrier' button. Problem is it creates the text boxes within the same table row as previously created boxes. It should create in new table row. Code is below and if you see anything else you would change please provide for optimization. And Thanks. Code below. <script runat="server"> Private Sub Page_Load
8
4318
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)
4
2504
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in the table. I know that I can dynamically add controls (eg a textbox) to the page controls collection of a web form in a server event which will then be rendered onto the form, as in the following snippet: System.Web.UI.WebControls.TextBox...
2
2215
by: Quentin Huo | last post by:
Hi: I have a user control and I want to dynamically create a Label control and TextBox control when the button "add more author name" is clicked. I did like this: 1. there is a "PlaceHolder" control "ph" in the user control; 2. create a Label control and TextBox control when in the "add" button
2
2422
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 is a dropdownlist control on the page, I add dynamically extra rows to the table. For instance, if the ddlSPType selected item is Aviation Company, an extra row containing a cell with the textbox control txtAircrafts is added to the HTML table...
2
2917
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...
0
2412
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event, which I am). I now want to read the text/values of those controls. I have found out that I can read the values if I wait until Page_Load, but then I have the same questions showing up again (along with the new questions) and I do not want them to....
1
4915
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have set text boxes and labels inside the table rows. I then added a button. All of these are done through code. The problem that i am having is i can get the value from a text box with resides inside the first panel (out side of panel that is...
1
1755
by: mazdotnet | last post by:
Hi all, I have Repeater dynamically adding textboxes to a placeholder and connecting it to AjaxControlToolkit.PopupControlExtender which works fine. I'm adding the textboxes using the following TextBox tbxQty = new TextBox(); tbxQty.ID = "tbxQty" + id; phUserInput.Controls.Add(tbxQty);
0
9731
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7671
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4342
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
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
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.