Click here to Skip to main content
15,878,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project I need to create 2 textboxes dynamically when clicking on add button,so when click on add button I need to generate 2 textboxes side by side with same position of side by side textboxes?

So please give me the solution

additional information copied from non-solution below
Actually I am getting the controls dynamically on my page.Here I need to get with equal gap and position which I mentioned above?

additional information copied from non-solution below 2
I am just using web forms only there I need to get 2 texboxes dynamically when clicking add button and next when clicking add button it should generate two textboxes adjascent with same as the position below.
Updated 21-Nov-13 23:17pm

Share this answer
Nelek 22-Nov-13 4:01am    
Obviously not ;P
CPallini 22-Nov-13 4:04am    
I see you are perceptive! :-)
Read and modify code as you want.
//Declaring the variable with limit
int n=1;
for (int i=0;i<n;i++)
TextBox MyTextBox=new TextBox();
//Assigning the textbox ID name
MyTextBox.ID = "txtb_" + i;
MyTextBox.Width = 540;
MyTextBox.Height = 60;
MyTextBox.TextMode = TextBoxMode.MultiLine;
Share this answer

You can build the html content from server side,

Initially define the div section in page like this with runat=server mode should be set
<div id="dynamicContent" runat="server">
//Our dynamic text box content is going to come here, which we gonna build it from server side.

Server side code to create dynamic controls with same with adjacent to another one
public void clickMe_click(object sender, EventArgs e)
           int count=1; //used to name the textbox id
           StringBuilder dynTxtBoxs = new StringBuilder();
           if (!IsPostBack)
               dynTxtBoxs.Append(@"<table id='dynTbl' runat='server'> <tr> <td>");
               dynTxtBoxs.Append(@"<input type='Text' runat='server' id='dynTxtBx_'" + count + "/>");
               dynTxtBoxs.Append(@"<input type='Text' runat='server' id='dynTxtBx_'" + count + "/>");
               dynamicContent.InnerHtml = Convert.ToString(dynTxtBoxs);

Now you can see the text box will be dynamically loaded on your page.
You need to work on appending extra controls on another click of a button.

Hope this helps you a bit.

Share this answer
winforms use

in web application use
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900