在web项目开发中,我们经常会从一个页面 传递大量的参数到另外一个页面,当参数很多的时候我们不能通过url直接传递过去,因为这样传递的参数有限,那么有木有其他的方法呢,当然有。我们可以用一个html页面作为中间页,把传递到HTML页面的数据通过post 请求 post到另外一个ASPX页面。实现在ASP.NET中实现跨页面大批量数据传递。废话少说,直接上代码:
父页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="WebAppTest.index" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>父页面</title>
<script language="javascript" type="text/javascript">
function ShowDividePage() {
var params = new Object();
params.Keys = "1234567890";
params.Code = "qwertyuioplkjhgfdsazxcvbnm";
var sFeature = "dialogWidth:500px; dialogHeight:250px;center:yes;help:no;resizable:no;scroll:auto;status:no";
var url = "Pop.htm?sysid=" + Math.random();
window.showModalDialog(url, params, sFeature);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="btn_Show" value="弹出" onclick="ShowDividePage();" />
</div>
</form>
</body>
</html>
HTML中间页:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML中间页</title>
<script language="javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
window.name = "submitForm";
var keys = window.dialogArguments.Keys;
var code = window.dialogArguments.Code;
$("#hdKeys").val(keys);
$("#hdCode").val(code);
$("#submitForm").submit();
});
</script>
</head>
<body>
<form id="submitForm" action="Show.aspx" method="post" target="submitForm">
<input type="hidden" id="hdKeys" name="hdKeys" />
<input type="hidden" id="hdCode" name="hdCode" />
</form>
</body>
</html>
接收参数 子页面:
直接在page_Load事件中接收:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebAppTest
{
public partial class Show : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string keys = Request.Form["hdKeys"];
string Code = Request.Form["hdCode"];
Response.Write(keys);
Response.Write(Code);
}
}
}