HTML頁面做中間頁跳轉傳遞參數


     在web項目開發中,我們經常會從一個頁面 傳遞大量的參數到另外一個頁面,當參數很多的時候我們不能通過url直接傳遞過去,因為這樣傳遞的參數有限,那么有木有其他的方法呢,當然有。我們可以用一個html頁面作為中間頁,把傳遞到HTML頁面的數據通過post 請求 post到另外一個ASPX頁面。實現在ASP.NET中實現跨頁面大批量數據傳遞。廢話少說,直接上代碼:

      父頁面:

   

 1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="WebAppTest.index" %>
 2 
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 4 
 5 <html xmlns="http://www.w3.org/1999/xhtml">
 6 <head runat="server">
 7     <title>父頁面</title>
 8     <script language="javascript" type="text/javascript">
 9         function ShowDividePage() {
10                 var params = new Object();
11                 params.Keys = "1234567890";
12                 params.Code = "qwertyuioplkjhgfdsazxcvbnm";
13                 var sFeature = "dialogWidth:500px; dialogHeight:250px;center:yes;help:no;resizable:no;scroll:auto;status:no";
14                 var url = "Pop.htm?sysid=" + Math.random();
15                 window.showModalDialog(url, params, sFeature);
16         }
17     </script>
18 </head>
19 <body>
20     <form id="form1" runat="server">
21     <div>
22     <input type="button" id="btn_Show" value="彈出" onclick="ShowDividePage();" />
23     </div>
24     </form>
25 </body>
26 </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);
        }
    }
}

效果如下:

 

 

 

 點我下載

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM