A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

假设ParentForm.aspx 页面上有TextBox1文本框和Open按钮
点击Open按钮弹出SubForm.aspx,SubForm.aspx页面上有TextBox1文本框和Close按钮
点击Close按钮关闭SubForm.aspx页面,并把子页面SubForm.aspx文本框的值显示到父页面ParentForm.aspx 的文本框上。
父窗体前台代码:

代码如下 复制代码
      <script type="text/javascript">
        function OpenSubForm(ret) {
            var strPath = "http://www.111Cn.NeT /subForm.aspx"
            var nHeight = 500
            var nWidth = 500
            var feature
            feature = "Height= " + nHeight + ",Width=" + nWidth + ",top=30,Left=30";
            feature += ",dependent=yes,location=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no;";
            window.open(strPath+"?Ret_Form=Form1&Ret_Value="+ret,'subForm',feature).focus();
            return false;
        }
    </script>
父窗体后台代码:

代码如下 复制代码
private void Page_Load(object sender, System.EventArgs e)
        {
            // ペ?ジを初期化するユ?ザ? コ?ドをここに?啡毪筏蓼?br />             this.Button1.Attributes.Add("onClick","return OpenSubForm('TextBox1');");
        }
子窗体后台代码:

代码如下 复制代码
        private void Button1_Click(object sender, System.EventArgs e)
        {
            string strScript =string.Empty;
            string strRetForm = String.Empty;
            string strRetValue=String.Empty;
            strRetForm=Request.Params["Ret_Form"];
            strRetValue=Request.Params["Ret_Value"];
            if (strRetForm == string.Empty)
            {
                strRetForm= "document.forms[0]";
            }
            strScript = "<script language=javascript>";
            strScript += "window.opener." + strRetForm;
            strScript += "." + strRetValue + ".value='" + this.TextBox1.Text.Trim() + "';";
            strScript += "window.close();";
            strScript += "</script>";
            Response.Write(strScript);
        }

上面是js其实也就是页面传值了,下面我把一些页面传值的代码发给大家参考。
页面间传值的几种方式 .
下面的代码片断演示了如何实现这个方法:
  源页面WebForm1.aspx.cs中的部分代码:
代码如下 复制代码
private void Button1_Click(object sender, System.EventArgs e)
{
     string url;
     url="WebForm2.aspx?name=" + TextBox1.Text + "&email=" + TextBox2.Text;
     Response.Redirect(url);
}
目标页面WebForm2.aspx.cs中的部分代码:
private void Page_Load(object sender, System.EventArgs e)
{
     Label1.Text=Request.QueryString["name"];
     Label2.Text=Request.QueryString["email"];
}
使用Session变量
源页面WebForm1.aspx.cs中的部分代码:
代码如下 复制代码
private void Button1_Click(object sender, System.EventArgs e)
{
     //textbox1 and textbox2 are webform
     //controls
     Session["name"]=TextBox1.Text;
     Session["email"]=TextBox2.Text;
     Server.Transfer("WebForm2.aspx");
}

  目标页面WebForm2.aspx.cs中的部分代码:
代码如下 复制代码
private void Page_Load(object sender, System.EventArgs e)
{
     Label1.Text=Session["name"].ToString();
     Label2.Text=Session["email"].ToString();
     Session.Remove("name");
     Session.Remove("email");
}
上面两种是常用的其它的就不介绍了,大家可自行去参考

4 个回复

正序浏览
宁滥勿缺
回复 使用道具 举报
光代码有什么用。。发点原理~
回复 使用道具 举报
支持分享~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马