0
這是我的第一篇文章。現在我已經有幾天遇到麻煩了。我有這樣的HTML代碼:獲取Javascript生成的文本輸入值,並使用.Net存儲它#
<fieldset>
<legend>Certifictions</legend>
<div runat="server" id="divCert">
<input runat="server" type="button" id="btnAddCert" class="Botones" value="Agregar Certificación" onclick="AddCertification()" />
<input runat="server" type="button" id="btnRemoveCert" class="Botones" value="Quitar Certificación" onclick="RemoveCert()" />
<br/>
</div>
</fieldset>
正如你所看到的,我通過JavaScript添加和刪除文本字段divCert
。這是代碼:
var count1=0;
function AddCertification() {
document.getElementById("divCert").innerHTML +=
"<input type='Text' runat='server' name='txCert_" +
(count + 1) + "' class='textBox' id='txCert" + (count1 + 1) +
"' placeholder='Insert Text'/>";
count1 = count1 + 1;
}
function RemoveCert() {
var parent;
var eleRemove
if (count1 > 0) {
parent = document.getElementById("divCert");
eleRemove = document.getElementById("txCert" + (count1).toString());
parent.removeChild(eleRemove);
count1 = count1 - 1;
}else {
window.alert("There's nothing to remove");
}
}
現在,我想要做的就是在aspx.cs文件中的代碼隱藏生成的文本框的值,儲存,並將其寫入到文件中。這樣的事情:
List<Object> list = new List<object>();
foreach(TextBox found in divCer.Controls){
list.Add(found.Value);
}
我知道代碼不會工作,但類似的東西是我想要做的每個文本框生成的值。
謝謝你的幫助。這很有幫助。並解決了我的問題。 – Richard
[when-someone-answers](http://stackoverflow.com/help/someone-answers) –