asp.net模式窗口传值并返回

本文介绍如何在ASP.NET应用程序中使用弹出窗口进行数据交互。具体包括从主页面传递数据到弹出页,以及从弹出页返回数据到主页面的方法。此方案适用于需要在两个页面间临时交换信息的场景。

将 a.aspx的按钮触发,将TextBox值传到b.aspx(弹出的模式窗口)的TextBox中,当点击b.aspx上的按钮时将其页面中的TextBox的值返回到a.aspx中的TextBox中.

 

代码实现

a.aspx
//頁面上有兩個控件:文本框:TextBox1,按鈕:Button1
protected   void   Page_Load(object   sender,   EventArgs   e)
        {              
                Button1.Attributes.Add( "onclick ",       "var       st=window.showModalDialog( 'user.aspx?val= '+document.all( 'TextBox1 ').value);document.all( 'TextBox1 ').value=st;return       st; ");          
        }          
        protected   void   Button1_Click(object   sender,   EventArgs   e)
        {
                RegisterStartupScript( "key ",       " <script> window.opener=null;window.close(this); </script> ");    
        }

//b.aspx頁面,有三個控件:文本框:TextBox1,按鈕1:ok,按鈕2:Cancel
protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                string   str;
                if   (!IsPostBack)
                {
                        str   =   Request.QueryString[ "val "].ToString();
                        TextBox1.Text   =   str;
                }          

        }
        protected   void   ok_Click(object   sender,   EventArgs   e)
        {
                string   str   =   " <script> window.returnValue=document.all( 'TextBox1 ').value;window.opener=null;window.close(); </script> ";
                ClientScriptManager   cs   =   Page.ClientScript;
                cs.RegisterStartupScript(this.GetType(),   " ",   str,   true);
        }
        protected   void   cancle_Click(object   sender,   EventArgs   e)
        {
                string   str   =   " <script> window.opener=null;window.close(this); </script> ";
                ClientScriptManager   cs   =   Page.ClientScript;
                cs.RegisterStartupScript(this.GetType(),   " ",   str,   true);
        } 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值