.NET中利用js让子窗体向父页面传值的实现方法

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了.NET中利用js让子窗体向父页面传值的实现方法脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

子页面C#后台代码:

复制代码 代码如下:

/// <summary>&nbsp; 
     /// 将设置好的值赋给父页面  
     /// </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>

脚本宝典总结

以上是脚本宝典为你收集整理的.NET中利用js让子窗体向父页面传值的实现方法全部内容,希望文章能够帮你解决.NET中利用js让子窗体向父页面传值的实现方法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: