Dynamically generated Textboxes on textchanged Event and fetching data from them on Button Click


Dynamically generated Textboxes on textchanged Event and fetching data from them on Button Click



Complete Source code of Default3.aspx



<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!
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>

No of Textboxes:
<asp:TextBox ID="txtNo" runat="server"
ontextchanged="txtNo_TextChanged" AutoPostBack="True"></asp:TextBox>
<asp:Panel ID="Panel1" runat="server">
<br />

</asp:Panel>
<br />
<asp:Button ID="btn" runat="server" Text="Submit" onclick="btn_Click" />
</div>
</form>
</
body>
</
html>
------------------------------------------------------------------------------------------

Complete Code of Default.aspx.cs Page



using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public
partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void txtNo_TextChanged(object sender, EventArgs e)
{

int a = Convert.ToInt32(txtNo.Text);

for (int i = 0; i < a; i++)
{
TextBox tempBox = new TextBox();
tempBox.ID =
"txtBox_" + (i + 1).ToString() ;
Panel1.Controls.Add(tempBox);



}

}
protected void btn_Click(object sender, EventArgs e)
{

int a = Convert.ToInt32(txtNo.Text);
for (int i = 0; i < a; i++)
{

TextBox tempBox = new TextBox();
string ss = Request.Form["txtBox_" + (i + 1).ToString()].ToString();
if (tempBox != null)
{
Response.Write(
"<table border=1px; Width=60px ><tr><td>"+ ss + "<br> " + "</td></tr></table>" );
}

}

}
}



Ebook Download
View all
Learn
View all