在父页面Parent.aspx点击弹出第二个页面,将会弹出Child.aspx子页面,在子页面中输入需要传入到Parent.aspx的值点击确认,则可以把Child.aspx子页面输入的值传到Parent.aspx上的控件上。
Parent.aspx的HTML为:

<%@ Page language="c#" Codebehind="Parent.aspx.cs" AutoEventWireup="false" Inherits="TestToParent.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title>WebForm1</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        <script language="javascript">

// ------------------弹出window.open窗口--------------------
function openwin(fileName,type,window_width,window_height,property)

    var top  = (window.screen.availHeight-window_height)/2;
    var left = (window.screen.availWidth-window_width)/2;
    var newwindow;
    if (window_width=="" && window_height=="")
    {
       if (type=="0")
       {
           newwindow=window.open(fileName,"","left="+left+",top="+top+","+property);
       }
       else
       {
           newwindow=window.open(fileName,"","left=0,top=0,"+property);
       }
    }
    else
    {
    if (type=="0")
    {
        newwindow=window.open(fileName,"","left=0,top=0,height="+window_height+",width="+window_width+","+property);
    }
    else
    {
        newwindow=window.open(fileName,"","left="+left+",top="+top+",height="+window_height+",width="+window_width+","+property);
    }
       
    }
    return newwindow;
}

function openwinsimp(fileName,window_width,window_height)


    //alert(fileName);
    var newwindow=openwin(fileName,'1',window_width,window_height,'resizable=no,scrollbars=auto,status=yes,toolbar=no,menubar=no,location=no');
    newwindow.focus();
    
    return newwindow;
}

        </script>
        <script>
        function getid()
        {

          var id = new String(window.location.href);
          //alert(id);

            if( id.indexOf("id=", 1) ==-1 )
            {
              id=-1;
             

            }
            else
            {
               
                id = parseInt( id.substr( id.indexOf("id=", 1) + 3 ) );
            }
           // alert(id);
             return id;
             
           
          }
          
          
        </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <a href="#" onclick="openwinsimp('./Child.aspx?id='+getid()+'&amp;type=d1&amp;ctrl1ID=txt_Child',1024,768)">
                弹出一个页面</a>
            <asp:TextBox id="txt_Child" style="Z-INDEX: 101; LEFT: 232px; POSITION: absolute; TOP: 80px"
                runat="server"></asp:TextBox>
            <asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 96px; POSITION: absolute; TOP: 32px" runat="server">第一个页面</asp:Label>
            <asp:Label id="Label2" style="Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 88px" runat="server">你在第二个页面输入的是:</asp:Label>
        </form>
    </body>
</HTML>

预览如下:

<%@ Page language="c#" Codebehind="Child.aspx.cs" AutoEventWireup="false" Inherits="TestToParent.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title>WebForm2</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <FONT face="宋体">
                <asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 120px; POSITION: absolute; TOP: 128px" runat="server"
                    Text="Button"></asp:Button>
                <asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 96px; POSITION: absolute; TOP: 88px" runat="server"></asp:TextBox>
                <asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 0px; POSITION: absolute; TOP: 96px" runat="server">第二个页面</asp:Label></FONT>
        </form>
    </body>
</HTML>

.CS代码:

private void Page_Load(object sender, System.EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            if (Request.Params["ctrl1ID"] != null)
            {
                ViewState["ctrl1ID"] = Request.Params["ctrl1ID"].Trim();

            }
        }

        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /**//// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {    
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        /**//// <summary>
        /// 生成script脚本,完成对父窗口控件的赋值
        /// </summary>
        /// <param name="value1">控件1的值</param>
        /// <param name="value2">控件2的值</param>
        /// <returns></returns>
        private string MakeScriptStr(string text)
        {

            //value= "  [" + value + "]";
            string result = "<script>";

            result += "window.opener.document.all('" + ViewState["ctrl1ID"] + "',0).value='" + text + "';";
            result += "window.close();";
            result += "</script>";

            return result;
        }
        private void Button1_Click(object sender, System.EventArgs e)
        {
            string strScript = this.MakeScriptStr(this.TextBox1.Text);
            Page.RegisterStartupScript("return1", strScript);
        
        }

转载于:https://www.cnblogs.com/hzuIT/articles/761310.html

子页面赋值给父页面的控件方法相关推荐

  1. 子页面赋值给父页面:window.opener.document.getElementById

    window.opener 返回的是创建当前窗口的那个父窗口的引用,比如点击了a.htm上的一个链接而打开了b.htm,然后我们打算在b.htm上输入一个值然后赋予a.htm上的一个id为" ...

  2. 非vue子页面 调用vue父页面方法

    由于要使用之前项目使用的页面,需要从非vue iframe子页面调用vue项目 1.父页面 <iframe :src="value.urlPath" frameborder= ...

  3. 父页面调用子页面方法, 子页面加载父页面传送的数据

    先看效果图就明白需求了: 点击search查询结果集, 点击某一条将该条的其他信息分别加载到tab1和tab2中, 即net bill和other amount这两个tab. 点击clear清空查询条 ...

  4. window.showModalDialog关闭子页面后刷新父页面

    父页面方法: function addbz(id){         var url="${ctx}/erp/pmDesign/pmDesign/addBZ.ht?id="+id; ...

  5. php退出页面父元素,jQuery中弹出iframe内嵌页面元素到父页面并全屏化的实例代码...

    iframe和弹窗这些词对于js高手来说都是耳熟能详的东西,作为一个新人来说,还在学习阶段的我就在工作中遇到这么一个奇葩的需求,要在引入的iframe页面里做一个全屏化的功能. 粗略一看,这还不容易, ...

  6. layer中嵌套的页面如何操作父页面_layui框架中layer父子页面交互详细解说

    本文主要介绍了layui框架中layer父子页面交互的方法,结合实例形式分析了layer父子页面交互的常用技巧以及layer弹出多个iframe找到父页面的操作方法,需要的朋友可以参考下,希望给大家的 ...

  7. WPF查找子控件和父控件方法

    原文:WPF查找子控件和父控件方法 public List<T> GetChildObjects<T>(DependencyObject obj, string name) w ...

  8. 弹出框页面中使用jquery.validate验证控件

    弹出框页面中使用jquery.validate验证控件有几个问题需要解决: 1,弹出框的提交事件完成后如何关闭弹出框页面? 2,提交不成功如何返回当前页? 3,如果知道验证事件成功? 之前笔者都是JS ...

  9. jQuery如何去判断页面是否有父页面?

    jQuery如何去判断页面是否有父页面?   是要判断当前页面是否被嵌入在frame里吗? 1 2 3 if (top != self) {     alert('我在框架里'); } 转载于:htt ...

  10. selenium Element is not clickable because another element obscures it — 点击被页面上其他元素遮住的控件,亲试有效!!!

    点击被页面上其他元素遮住的控件 使用WebDriver点击界面上Button元素时,如果当前Button元素被界面上其他元素遮住了, 或没出现在界面中(比如Button在页面底部,但是屏幕只能显示页面 ...

最新文章

  1. [python]目录及文件操作
  2. ETL MySQL in Oracle ODI 12c
  3. html5声频audio和视频video
  4. python 依赖库管理 包管理 pipreqs、pigar、pip-tools、pipdeptree 简介
  5. 大山深处,有一所希望学校
  6. 记录 之 tf.data进行数据集处理常用的几个函数介绍
  7. JEP 342:JVM和幽灵
  8. 站在Java的角度看LinkedList
  9. Delphi多媒体设计之播放WAVE文件(API)
  10. AliDDNS 阿里云动态域名服务 实用工具
  11. 谷露猎头系统3.0新功能:Mapping模块,助你轻松画出动态组织架构图
  12. 编程序找出1000之内的所有完数
  13. 译文:在闭包中使用循环变量是有害的
  14. Cholesky分解(Matlab代码实现)
  15. CodeForces - 514B Han Solo and Lazer Gun
  16. 常见安全设备总结(IDS、IPS、上网行为管理、网闸、漏扫、日志审计、数据库审计、堡垒机等)
  17. man fputc fputs putc putchar puts
  18. java csv 数组_使用csv文件的输入填充结构数组
  19. 转:数据库访问性能优化
  20. Java SpringBoot发送邮件,自定义发件人昵称/名称

热门文章

  1. linux下用c语言写黄金矿工,c语言课程设计黄金矿工(提高篇)
  2. springcloud断路器修改熔断时间_SpringCloud(四)Hystrix服务降级,服务熔断
  3. open cv python_Open CV非常牛逼!众所周知!今天就来见识一下它究竟有多牛逼!
  4. java调用python脚本_python脚本估算Java线程池参数配置
  5. 一、optimizer_trace介绍
  6. 力扣-386 字典序排数
  7. Android 在Activity界面下滑动ViewPager实现两个Fragment之间的切换?
  8. Android RecyclerView实现长按弹出PopupMenu菜单
  9. RK3288_Android7.1平台基于DRM框架的LCD开发
  10. [CF809E] Surprise me!