public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Page_PreRender(object sender, EventArgs e) { if (IsPostBack) { btnCreate_Click(sender, e); } } protected void btnCreate_Click(object sender, EventArgs e) { DivTextBoxCreator.Controls.Clear(); HtmlTable htable = new HtmlTable(); htable.BgColor = "Yellow"; for (int i = 1; i <= int.Parse(TextBox1.Text); i++) { HtmlTableRow hRow = new HtmlTableRow(); HtmlTableCell hCell = new HtmlTableCell(); TextBox txtGenerator = new TextBox(); txtGenerator.Text = "TextBox : " + i; hCell.Controls.Add(txtGenerator); hRow.Controls.Add(hCell); htable.Controls.Add(hRow); } DivTextBoxCreator.Controls.Add(htable); // create a Save Button Button buttonSave = new Button(); buttonSave.ID = "buttonSave"; buttonSave.Text = "Save"; buttonSave. önClientClick = "return validate()"; buttonSave.Click += new EventHandler(buttonSave_Click); buttonSave_Click(sender, e); DivTextBoxCreator.Controls.Add(buttonSave); } protected void buttonSave_Click(object sender, EventArgs e) { Response.Write("Test"); } }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <table> <tr> <td> Enter Number of TextBox</td> <td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td> </tr> <tr> <td> </td> <td style="margin-removed 40px"> <asp:Button ID="btnCreate" runat="server" Text="Create" Width="139px" onclick="btnCreate_Click" /> </td> </tr> <tr> <td> </td> <td style="margin-removed 40px"> </td> </tr> <tr> <td> </td> <td style="margin-removed 40px"> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <div id="DivTextBoxCreator" runat="server"> </div> </ContentTemplate> </asp:UpdatePanel> </td> </tr> <tr> <td> </td> <td style="margin-removed 40px"> <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <div id="DivButtonCreator" runat="server"> </div> </ContentTemplate> </asp:UpdatePanel> </td> </tr> <tr> <td> </td> <td style="margin-removed 40px"> </td> </tr> </table> </div> </form> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)