子窗体给父窗体传值

最近做了一个子窗体给父窗体赋值的问题。做的很成功,虽然功能过于简单,心理有点喜悦

接下来看下例子:我有两个窗体,一个MainForm 父窗体  一个ChirdleFrom 子窗体

这个是父窗体的代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainForm.aspx.cs" Inherits="TestWeB.窗体赋值.MainForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        //打开新的窗体函数
        function OpenDialog(url, height, width) {
            window.showModalDialog(url + "&rdm=" + Math.random(), document, "dialogHeight: " + height + "px; dialogWidth: " + width + "px;edge: Raised; center: Yes; help: No; resizable: No; scrollbars:No;");
        }
        var resger = function () {
            //获取服务端控件的value
            var textvalue = document.getElementById("<%=TextBox1.ClientID%>").value;

            if (textvalue != "") {

                OpenDialog("ChildrenFrom.aspx?id=1&name="+textvalue+"&contorl=TextBox2", "598", "715");  //window.showModalDialog(");
            }
        }
   
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="resger();" />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

 

 

这个是子窗体的代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChildrenFrom.aspx.cs" Inherits="TestWeB.窗体赋值.ChildrenFrom" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function result() {
           //获取父窗体的对象
            var e = (window.parent.opener == undefined) ? dialogArguments : window.parent.opener.document;
           
            var id = '<%=Request.QueryString["id"]%>';//获取url中的Id参数
            var name = '<%=Request.QueryString["name"]%>';
            var contorl = '<%=Request.QueryString["contorl"]%>';
            //找到父窗体的dom对象,然后赋值(textbox2的text)
            e.getElementById(contorl).value = id + " -" + name + " " + document.getElementById('<%=t1.ClientID %>').value;
            //关闭窗体
            window.close();

        }
   
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        子窗体
        <asp:TextBox runat="server" ID="t1"></asp:TextBox>
        <a href="#" οnclick="result()">确定</a>
      <%--  注销是因为他会产生刷新的功能,所以采用了客户端控件--%>
        <%-- <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="result()" />--%>
    </div>
    </form>
</body>
</html>

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值