窗口传值之大量数据传递解决方案

 之前在一个项目里遇到这样的情况,就是有一个文本框,旁边有一个选择人员的按钮,每次当点击选择人员的按钮里要求把之前选择的内容加载进去,刚开始是通过url传值的,可是后来当人员名称超过1000多个字符的时候,url根本就传不过去,后来想到用Session的方式,可是考虑到性能的问题,还是放弃了这种方式,最终用如下的方式实现的,希望对大家有所帮助,如果有更好的方式,也请留言告诉我。

1:前台.aspx页面(父窗体)的代码如下:

    <form id="form11" method="post" enctype="multipart/form-data" runat="server">
       <asp:TextBox ID="UserID" style="display:none" runat="server" Text=""></asp:TextBox>

       <input id="txt_AreaHidden1" visible="true" style="display: none" type="text" name="txt_AreaHidden1"
           runat="server"><input onclick="ChooseWho();" type="button" value="选择收件人">

  </form>

2:前台js代码:

     function ChooseWho()
   {

    var revalue;

   document.all.UserID.value=document.all.txt_AreaHidden1.value;
          revalue = window.showModalDialog('../Include/ChoosePriUnsers.aspx',window,'dialogHeight:365px;dialogWidth:720px;               dialogTop:screen.height/2;dialogLeft:screen.width/2; edge:sunken ; center: Yes; help: No; resizable: No; status: No; scroll:yes;');

  }

3:子窗体在加载时得到父窗体中保存在UserID中的值;

   function GetUserID()
    {
        if(window.dialogArguments.document.all.UserID!=null)
        {
                  document.all.hidUserID.value = window.dialogArguments.document.all.UserID.value;
            document.all["btn1"].onclick();
        }
  
    }

4:后台注册js脚本

   private void Page_Load(object sender, System.EventArgs e)
        {

          if (!IsPostBack)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script>GetUserID();</script>");

            }

         }

原文地址:https://www.cnblogs.com/zhangzt/p/1628748.html