.NET中利用js让子窗体向父页面传值

本文介绍了C#后台代码如何通过JavaScript实现与父页面的数据交互,具体展示了如何使用JavaScript字符串构建函数来获取并设置从子页面返回的数值和字符串数据,并在父页面中进行显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

子页面C#后台代码:
   /// <summary>
        /// 将设置好的值赋给父页面
        /// </summary>
        /// <param name="count">需要传递的值</param>
        void SetValueToParentPage(int count, string strPersons)
        {
            StringBuilder jsStr = new StringBuilder();
            jsStr.Append(" var retValue = new Object();");
            if (count == 0)
            {
                jsStr.AppendFormat("retValue = null;");
            }
            else
            {
                jsStr.AppendFormat("retValue.Nums='{0}';", count);
                jsStr.AppendFormat("retValue.Names='{0}';", strPersons);
            }
            jsStr.Append("window.returnValue = retValue;window.close();");

            ClientScript.RegisterStartupScript(GetType(), "close", jsStr.ToString(), true);
        }


父页面前台js:

  function OpenPerChoose(url) {
            var openobj = window;
            if (typeof (window.dialogArguments) == "object") {
                openobj = window.dialogArguments;
            }
            var returnValue = showPopWin(url, 800, 600, openobj);
            if (returnValue != null) {
                document.getElementById("<%=txtQualifiedNums.ClientID %>").value = returnValue.Nums;
            }
        }

//弹出窗口
function showPopWin(url, width, height, returnFunc) {
    width = parseInt(width) + 30;
    height = parseInt(height) + 30;
    return window.showModalDialog(url + "&Datetime=" + GetTime(), document, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:0;status:0;scroll:auto;center:1;resizable:1;");
}

 

      <th style="width: 100px;">
                培训合格人数:
            </th>
            <td style="width: 50px;">
                <asp:TextBox ID="txtQualifiedNums" runat="server" Width="50px" ReadOnly="true"></asp:TextBox>
            </td>

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邹琼俊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值