473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to send data to the server from dynamically created html controls

Hii,

currently i am working on an apliction(ASP.NET/C#) that creates dynamic html rows which contain six html text boxes and a html dropdowllist. At the time of page load the web page contain six server side text boxes and a serverside drop down list. and a html "Addrow" buton which create client side textboxes and dropdown list dynamichally Now i am meeting a problem of passing values from dynamichally created html controls to Server Side
Very Urgent
please help me
code follows

[HTML]<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">


var ar=new Array();
var ar2=new Array();
var len;
function LoadDdl()
{
debugger;
if(document.getElementById('Select1')!=null)
{
len=document.getElementById('Select1').options.len gth;

for(i=0;i<len;i++)
{

ar[i]=document.getElementById('Select1').options[i].innerHTML;
ar2[i]=document.getElementById('Select1').options[i].value;
}
}
}

function addRow()
{
var ni = document.getElementById('trContent');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value -1)+ 2;
numi.value = num;
//add a row to the rows collection and get a reference to the newly added row
var newRow = document.all("tblGrid").insertRow();

//add 7 cells (<td>) to the new row and set the innerHTML to contain text boxes

var oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' id="+"slno"+num+" name='t1' style='width: 72px'>";


oCell = newRow.insertCell();
//oCell.innerHTML = "<input type='text' name='t2' style='width: 72px'>";
//oCell.innerHTML = "<select id='ddl' name='t2' style='width: 72px'>";
var selecttg="<select id="+"ddl"+num+"' style='width:72px'>";
var optiontg="";
for(i=0;i<len;i++)
{

//var sel=document.getElementById('ddl');
var optiontg =optiontg+"<option value="+ar2[i].toString()+">"+ar[i].toString()+"</option>";

}
var fullbotle=selecttg+optiontg;
oCell.innerHTML=fullbotle+"</select>";
//oCell.innerHTML="</select>";
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' id="+"number"+num+" name='t3' style='width: 72px'>" ;
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' id="+"qty"+num+" name='t4' style='width: 72px'>";

oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' id="+"rate"+num+" name='t5' style='width: 72px'>";

oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' id="+"discount"+num+" name='t6' style='width: 72px'>";
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' id="+"Amount"+num+" name='t7' style='width: 72px'>";
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='button' value='Delete' onclick='removeRow(this);'/>";
}

//deletes the specified row from the table
function removeRow(src)
{
/* src refers to the input button that was clicked.
to get a reference to the containing <tr> element,
get the parent of the parent (in this case case <tr>)
*/
var oRow = src.parentElement.parentElement;

//once the row reference is obtained, delete it passing in its rowIndex
document.all("tblGrid").deleteRow(oRow.rowIndex);
}
</script>
</head>
<body onmouseover="LoadDdl()">
<input type="hidden" value="0" id="theValue" />
<form id="form1" runat="server">
<div>
<table id="tblGrid" style="table-layout:fixed" runat="server">
<tr>
<td >
SLNo</td>
<td >
Item</td>
<td >
Number</td>
<td >
Quantity</td>
<td >
Rate</td>
<td >
Discount</td>
<td>
Amount</td>
</tr>
<tr id="trContent">
<td >
<input id="Text1" type="text" runat="server" style="width: 84px" /></td>
<td >
<select id="Select1" runat="server" style="width: 102px"></select></td>
<td >
<input id="Text3" type="text" runat="server" style="width: 72px" /></td>
<td >
<input id="Text4" type="text" runat="server" style="width: 66px" /></td>
<td >
<input id="Text5" type="text" runat="server" style="width: 66px" /></td>
<td >
<input id="Text6" type="text" runat="server" style="width: 66px" /></td>
<td>
<input id="Text7" type="text" runat="server" style="width: 72px" /></td> <td ><input type="button" value="Delete" onclick="removeRow(this);" /></td>
</tr>

</table>
<hr/>
<input type="button" value="Add Row" onclick="addRow();" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Save" /></div>
</form>
</body>
</html>
[/HTML]
Thanking you and regards
Balu
Apr 2 '08 #1
3 2986
acoder
16,027 Expert Mod 8TB
As long as you've named your elements and appended them within the form, the values should be submitted when you submit the form.
Apr 2 '08 #2
can u pls give an example using dynamic contol
Apr 2 '08 #3
acoder
16,027 Expert Mod 8TB
Does none of the data from the dynamically created elements get sent when the form is submitted or only some of the data?
Apr 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Russ | last post by:
I'm interested in setting up a web page where live data can be displayed in real-time on the web page. For example: I would like to display a (nice looking) graph of some data value versus time...
9
by: eswanson | last post by:
I have a web page I need to post a file plus some other fields to it. How can I do this from a asp.net page. I know I can send individual fields to the other page, but how do I send a file to the...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
7
by: Tom wilson | last post by:
I'm trying to create dynamic controls in ASP.Net. It's driving me nuts. I keep getting the error: Control '16' of type 'RadioButton' must be placed inside a form tag with runat=server. Dim...
3
by: Ferryandi | last post by:
hi, i have created a button link like this and attach it to placeholder in code behind linkbutton1 = New LinkButton linkbutton1.Text = "Link Button linkbutton1.ID = "Link1"...
4
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays...
3
by: pbd22 | last post by:
Hi. How do I add the runat=server attribute on a buttonfield link dynamically? thanks!
4
by: =?Utf-8?B?RHlsYW5TbWl0aA==?= | last post by:
I have a WebForm where I'm dynamically creating some controls and I'm having difficulty understanding how the state is being persisted and how to work with it. I've created a simplified example...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.