当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET 窗体间传值的方法

ASP.NET 窗体间传值的方法

2017年12月12日  | 移动技术网IT编程  | 我要评论
假设parentform.aspx 页面上有textbox1文本框和open按钮点击open按钮弹出subform.aspx,subform.aspx页面上有textbox
假设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 = "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)
        {
            // ページを初期化するユーザー コードをここに挿入します
            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);
        }

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网