hi,
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblQty" Text="Enter Quantity" runat="Server"></asp:Label>
<asp:TextBox ID="txtCreateTextBoxQty" runat="server"></asp:TextBox>
<asp:Label ID="lblDefaultVal" Text="Enter Default Value" runat="Server"></asp:Label>
<asp:TextBox ID="txtDefaultValue" runat="server"></asp:TextBox>
<asp:Button ID="btnCreateControls" runat="server" Text="Add" OnClick="btnCreateControls_Click" />
<asp:PlaceHolder ID="phControls" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
Code:
protected void btnCreateControls_Click(object sender, EventArgs e)
{
try
{
int intTextQty = int.Parse(txtCreateTextBoxQty.Text);
string strDefaultValue = txtDefaultValue.Text;
for (int i = 0; i < intTextQty; i++)
{
TextBox txt = new TextBox();
txt.ID = "txt" + i;
txt.Text = strDefaultValue;
phControls.Controls.Add(new LiteralControl("<br />"));
phControls.Controls.Add(txt);
phControls.Controls.Add(new LiteralControl("<br />"));
}
}
catch (Exception)
{
throw;
}
}