URgent!!! Collecting data from server side

G

Guest

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 collect the data from server side in the
Textboxes which i added dynamically from javascript, i am not able to do so.
Also i tried to bedug, the total no of rows in Html table does not reflect
the dynamically
added rows.

What i mean is, For Ex, If have one row in html tble, and i clciked the
Button twice. It adds 2 rows. Now the total no of rows are 3. But when i
dbug, it stiill shows Table.rows.count is 1.

Any help is appreciated.

Here is my code
Javascript to add rows dynamically
//Adding New Row IncMat
//
function addNewRowInCorrespondingTab1(){

try
{
addRowInIncMaterial();
}
catch(e)
{
alert("Problem in adding new row...");
window.status = "Problem in adding new row...";
return false;
}
return false;
}
//
function addRowInIncMaterial(){

var theTable;
var lastRow;
var row;
var cell;
var el;
var NoOfCol;
//
theTable = document.getElementById('IncomingMateTbl');
lastRow = theTable.rows.length - 1;
row = theTable.insertRow(2);
//
var DDLText = 'Select,Stage,Eng';
//
NoOfCol = parseInt(4);
for(i = 1; i <= (NoOfCol); i++)
{
if (i == 1)
{
aryDDLText = DDLText.split(",");
cell = row.insertCell(i - 1);
cell.setAttribute('align','center');
el = document.createElement('select');
el.setAttribute('Font-Size', '9pt');

el.setAttribute('name', 'IncMat' + (lastRow) + i);
el.setAttribute('id', 'IncMat' + (lastRow) + i);
//
for(id = 0; id < aryDDLText.length; id++)
{
if (id==0)
{
oNewOption = new Option();
oNewOption.text = aryDDLText[id];
oNewOption.value = '0';
}
else
{
oNewOption = new Option();
oNewOption.text = aryDDLText[id];
oNewOption.value = aryDDLText[id];
}
el.add(oNewOption,id);
cell.appendChild(el);
}
}
else
{
cell = row.insertCell(i - 1);
cell.setAttribute('align','center');
el = document.createElement('input');
el.setAttribute('type', 'text');
//
el.setAttribute('name', 'IncMat' + (lastRow) + i);
el.setAttribute('id', 'IncMat' + (lastRow) + i);
//
el.setAttribute('value', '');
el.setAttribute('size', '11');
el.setAttribute('Fontsize', '9pt');
cell.appendChild(el);
}
}
//
}
//

Server Side Code

Dim IncMatIdx As Integer
Dim ctr As Integer
Dim Ptr As New HtmlTableRow()
Dim inputTxt As New HtmlInputText()
Dim InputDDL As New DropDownList()

IncMatIdx = IncomingMateTbl.Rows.Count
For ctr = 1 To ctr <= IncMatIdx
Ptr = IncomingMateTbl.Rows(ctr)
'
InputDDL = CType(Ptr.Controls.Item(0).Controls.Item(0),
DropDownList)
DetailDataObj2.SetIncomingMat("IncMaterial",
InputDDL.SelectedItem.Value)
'
inputTxt = CType(Ptr.Controls.Item(1).Controls.Item(0),
HtmlInputText)
DetailDataObj2.SetIncomingMat("Batch", inputTxt.Value)

inputTxt = CType(Ptr.Controls.Item(2).Controls.Item(0),
HtmlInputText)
DetailDataObj2.SetIncomingMat("PCN", inputTxt.Value)

inputTxt = CType(Ptr.Controls.Item(3).Controls.Item(0),
HtmlInputText)
DetailDataObj2.SetIncomingMat("Qty", inputTxt.Value)
'
InfoObj.AddSMODetail(DetailDataObj2)
Next




Thx in advance
Sileesh
 
B

bruce barker

your approach is off. when the browser posts the page, it only sends
name/value pairs for input, select and textareas which are contained in the
posted form (html unlike asp.net supports more than 1 form per page).
changing table rows in client code will have no effect on the server
definition of the table.

your client code will have to fill in a hidden field with enough info for
you to recreate the client version of the table on the server side.

-- bruce (sqlwork.com)

Sileesh said:
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 collect the data from server side in the
Textboxes which i added dynamically from javascript, i am not able to do so.
Also i tried to bedug, the total no of rows in Html table does not reflect
the dynamically
added rows.

What i mean is, For Ex, If have one row in html tble, and i clciked the
Button twice. It adds 2 rows. Now the total no of rows are 3. But when i
dbug, it stiill shows Table.rows.count is 1.

Any help is appreciated.

Here is my code
Javascript to add rows dynamically
//Adding New Row IncMat
//
function addNewRowInCorrespondingTab1(){

try
{
addRowInIncMaterial();
}
catch(e)
{
alert("Problem in adding new row...");
window.status = "Problem in adding new row...";
return false;
}
return false;
}
//
function addRowInIncMaterial(){

var theTable;
var lastRow;
var row;
var cell;
var el;
var NoOfCol;
//
theTable = document.getElementById('IncomingMateTbl');
lastRow = theTable.rows.length - 1;
row = theTable.insertRow(2);
//
var DDLText = 'Select,Stage,Eng';
//
NoOfCol = parseInt(4);
for(i = 1; i <= (NoOfCol); i++)
{
if (i == 1)
{
aryDDLText = DDLText.split(",");
cell = row.insertCell(i - 1);
cell.setAttribute('align','center');
el = document.createElement('select');
el.setAttribute('Font-Size', '9pt');

el.setAttribute('name', 'IncMat' + (lastRow) + i);
el.setAttribute('id', 'IncMat' + (lastRow) + i);
//
for(id = 0; id < aryDDLText.length; id++)
{
if (id==0)
{
oNewOption = new Option();
oNewOption.text = aryDDLText[id];
oNewOption.value = '0';
}
else
{
oNewOption = new Option();
oNewOption.text = aryDDLText[id];
oNewOption.value = aryDDLText[id];
}
el.add(oNewOption,id);
cell.appendChild(el);
}
}
else
{
cell = row.insertCell(i - 1);
cell.setAttribute('align','center');
el = document.createElement('input');
el.setAttribute('type', 'text');
//
el.setAttribute('name', 'IncMat' + (lastRow) + i);
el.setAttribute('id', 'IncMat' + (lastRow) + i);
//
el.setAttribute('value', '');
el.setAttribute('size', '11');
el.setAttribute('Fontsize', '9pt');
cell.appendChild(el);
}
}
//
}
//

Server Side Code

Dim IncMatIdx As Integer
Dim ctr As Integer
Dim Ptr As New HtmlTableRow()
Dim inputTxt As New HtmlInputText()
Dim InputDDL As New DropDownList()

IncMatIdx = IncomingMateTbl.Rows.Count
For ctr = 1 To ctr <= IncMatIdx
Ptr = IncomingMateTbl.Rows(ctr)
'
InputDDL = CType(Ptr.Controls.Item(0).Controls.Item(0),
DropDownList)
DetailDataObj2.SetIncomingMat("IncMaterial",
InputDDL.SelectedItem.Value)
'
inputTxt = CType(Ptr.Controls.Item(1).Controls.Item(0),
HtmlInputText)
DetailDataObj2.SetIncomingMat("Batch", inputTxt.Value)

inputTxt = CType(Ptr.Controls.Item(2).Controls.Item(0),
HtmlInputText)
DetailDataObj2.SetIncomingMat("PCN", inputTxt.Value)

inputTxt = CType(Ptr.Controls.Item(3).Controls.Item(0),
HtmlInputText)
DetailDataObj2.SetIncomingMat("Qty", inputTxt.Value)
'
InfoObj.AddSMODetail(DetailDataObj2)
Next




Thx in advance
Sileesh
 

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,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top