ASp.net How to get textbox values generated byJavascript

S

Sandesh Daddi

You can use following code to get it work


<%@ Page Language="C#" AutoEventWireup="true"%>

<!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>

<script type="text/javascript" >

function createTextBox(event)
{

//Get the reference of DIV where we want to show textboxes
var dv = document.getElementById("dvTextBoxes");

//Create the Textbox and append that to DIV.
var tx = document.createElement("INPUT");
tx.name = "txt";
tx.value= "1";
dv.appendChild(tx);
}
</script>


<script type="text/C#" runat="server" >

protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Page.IsPostBack)
{
String strValues = Request.Form["txt"];

String[] strV = strValues.Split(',');

for (int i = 0; i < strV.Length; i++)
{
lblError.Text += strV.ToString() + "\n";
}
}
}
catch (Exception ex)
{
throw ex;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="btnAddText" value="Add text" onclick="createTextBox(event)" />
<div id="dvTextBoxes">
</div>
<asp:Button ID="btnSubmit" runat="server" Text="Submit"/>

<asp:Label ID="lblError" runat="server" ForeColor="RED" ></asp:Label>
</div>
</form>
</body>
</html>


Reply me if you want some thing else


Thank you
Saandesh Daddi
www.sanshark.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top