Vote count:
0
I am adding rows to a table in my ASPX page using JavaScript and it works fine, but when I submit the page, c# doesn't see newly added rows but only ones hardcoded in ASPX page.
ASPX
<table id="frmTable" runat="server">
<tr>
<td colspan="2">
<input type="button" title="Text" onclick="AddToForm('Text')" value="Text" />
<input type="submit" ID="btnSubmit" runat="server" Text="Submit" OnServerClick="btnSubmit_Click" />
</td>
</tr>
</table>
JavaScript function
function AddToForm(type) {
var tbl = document.getElementById("frmTable");
var row = tbl.insertRow();
var cell = row.insertCell();
cell.setAttribute("datatype", 'text');
cell.setAttribute('isrequired', 'no');
var field = document.createElement("input");
cell.appendChild(field);
}
C# code behind
protected void btnSubmit_Click(object sender, EventArgs e) { Response.Write(frmTable.Rows[0].Cells[0].Attributes["datatype"] + " -- " + frmTable.Rows[0].Cells[0].Attributes["isrequired"]); }
When I check row count in btnSubmit_Click event, frmTable only sees 1 row that has submit button, but doesn't see the row that has been successfully added by Javascript.
Please advise.
asked 50 secs ago
I am adding rows to table by javascript but when I submit the page, C# doesnt see added rows
Aucun commentaire:
Enregistrer un commentaire