Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
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 asp.net 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.
Posted
Updated 21-Nov-13 23:17pm
v3

 
Share this answer
 
Comments
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.
C#
//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;
this.Controls.Add(MyTextBox);
}
 
Share this answer
 
Hi,

You can build the html content from server side,

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

Server side code to create dynamic controls with same with adjacent to another one
XML
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 + "/>");
               count++;
               dynTxtBoxs.Append(@"<input type='Text' runat='server' id='dynTxtBx_'" + count + "/>");
               dynTxtBoxs.Append(@"</td></tr></table>");
               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.

Regards,
RK
 
Share this answer
 
winforms use
tablelayoutpanel

in web application use
<table></table>
 
Share this answer
 
v2

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