我有兩個頁面customer.aspx和customer_detail.aspc,每個頁面都有相應的代碼隱藏文件。目標是能夠將特定的表單元格的值從客戶發送到customer_detail。例如,以下JavaScript基於customer.aspx.cs文件中的BindTable方法動態地將表格呈現到customer.aspx上。 customer.aspx:C#從一個頁面發送表格單元格數據到另一個頁面
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "customer.aspx/BindCustomer",
data: "{}",
dataType: "json",
success: function(data) {
for (var i = 0; i < data.d.length; i++) {
$("#customer_table").append("<tr><td>"+'<a id = "anchor" href="customer_individual.aspx">' + data.d[i].customer_name +'</a>'+ "</td><td>" + data.d[i].customer_id +"</td><td>" + data.d[i].total_value + "</td><td>" + data.d[i].created_date + "</td></tr>");
}
},
error: function(result) {
alert("Error");
}
});
});
上述BindCustomer功能是一個用customer.aspx.cs一個WebMethod,它返回一個客戶陣列對象,顧客[],它被綁定到CUSTOMER_TABLE。注意,在上面,我在表的第一個td元素中有一個href,它將頁面重定向到customer_detail.aspx。
目標是在單擊customer_detail.aspx.cs鏈接後發送一個customer_name值,以便我可以查詢單獨存儲的客戶對象,並使用名稱並相應地填充頁面。什麼是最好的方法來完成這個?有關如何進行的任何建議將非常有幫助!
當你說,'發送數據到'頁面,你的意思是重定向用戶到該頁面並顯示或以某種方式引用該數據? –
是的,目前的鏈接工作,其中'customer_detail'頁面包含一些靜態字段,如文本框和標籤。用戶需要重定向到頁面以及值data.d [i] .customer_name,然後我可以使用它填充customer_detail頁面上的文本框 – skarred14
然後,這就是它的全部內容。只需將想要傳遞的值附加到查詢字符串中的網址即可。 –