您将无法从服务器端检索 jQuery 生成的文本框。如果服务器控件是在客户端创建的,则它们不存在。您可以做的是使用 JSON 来捕获文本框并回发页面。
这是我在类似情况下使用的示例代码:
function SubmitResources() {
var activeDiscipline = $('#<%=tcDisciplines.ClientID%> .ajax__tab_active').first().attr('id').replace(/\D/g, "");
var ctrID = $('#<%=hfCTRID.ClientID%>').val();
var ctrDescription = CKEDITOR.instances['<%=tbEditDescription.ClientID%>'].getData().replace(/[|]/g, "");
//before this part I retrieved the data from needed controls
var json = activeDiscipline + "|" + ctrID + "|" + ctrDescription + "|"; // here I add initial data into the JSON variable
$('#<%=tblEdit.ClientID%> .trRes').each(function () {
var resID = $(this).find("#resource").attr("name");
var resH = $(this).find(".resH").val();
var resC = $(this).find(".resC").val();
json += resID + ';' + resH + ';' + resC + '|'
}); //this loop goes through generated text boxes and appends the data with separators
var options = { //set JSON options
type: "POST",
url: window.location + "&Update=Resource", //append QueryString
data: json,
contentType: "application/json;charset=utf-8",
dataType: "json",
async: false
};
$.ajax(options); //Postback
}
将功能设置为按钮:
<asp:Button ID="btnEditSubmit" runat="server" Text="Submit" ValidationGroup="Edit" OnClientClick="SubmitResources()" />
转到您的 .aspx.vb 并处理 Init 事件
If Not IsNothing(Request.QueryString("Update")) Then
'If the query string was passed from jQuery, capture the JSON value and submit
Dim sr As New StreamReader(Request.InputStream)
Dim line As String = sr.ReadToEnd()
Dim resources As String() = line.Substring(0, line.Length - 1).Split("|")
'Do your magic here. Now 'line' looks like this: 0;10;100|1;20;200|2;200;2000. 'resources' is an array with values as so: 0;10;100 Loop through the array and get the needed data.
End If