主窗体与弹出窗体间传递数据

效果如图:

实现代码:

前台:

<script language="javascript">

function Popup(target,winWidth,winHeight,maxLength)

     {

         var popupWin = null;

         var winLeft; //弹出的窗口距离屏幕左边的像素

         var winTop;  //弹出的窗口距离屏幕顶部的像素

         var str;  //弹出窗口的窗体属性值

         //如果已经存在此弹出窗口,就关闭它

         if(popupWin != null)

         {

              popupWin.close();

         }

         if(maxLength == null)

         {

              maxLength = 0;

         }

         //是弹出的窗口水平居中于屏幕

         winLeft = (screen.width - winWidth) / 2;

         //是弹出的窗口垂直居中于屏幕

         winTop  = (screen.height - winHeight) / 2;

         //指定弹出窗口的外观属性

         str="width="+winWidth+",height="+winHeight+",top="+winTop+",left="+winLeft+",scrollbars=0,resizable=no";

         try

         {

              var popupStr = "";

                      

              popupWin = window.open('','popup',str);

              popupStr += "<html> /r/n";

              popupStr += " <head> /r/n";

              popupStr += "      <title>弹出窗体</title> /r/n";

              popupStr += "      <script language='javascript'> /r/n";

              popupStr += "          var maxLength="+maxLength+"; /r/n";

              popupStr += "          function GoBack() /r/n";

              popupStr += "          {    if( (maxLength != 0) & (document.all['txt'].value.length>maxLength) ) /r/n";

              popupStr += "               {    alert('你输入的字符长度超出范围!'); /r/n";

              popupStr += "                    return; } /r/n";

              popupStr += "               window.opener.document.all['"+target+"'].value=txt.value; /r/n";

              popupStr += "               window.close(); /r/n";

              popupStr += "          } /r/n";

              popupStr += "      </"+"script> /r/n"

              popupStr += " </head> /r/n";

              popupStr += "   <body bottommargin=0 topmargin=0 leftmargin=0 rightmargin=0> /r/n";

              popupStr += "      <center><textarea id=txt οnkeypress='javascript:if(event.keyCode==27)self.close();' style='width:"+(winWidth)+";height:"+(winHeight-25) +"'>";

              popupStr += "      </textarea> /r/n";

              popupStr += "      <input type=button id=btnSubmit value='OK' οnclick='GoBack()' style='width:60px'> /r/n";

              popupStr += "&nbsp;&nbsp;&nbsp;&nbsp;<input type=button value='Cancel' οnclick='window.close()' style='width:60px'> /r/n";

              popupStr += "   </center></body> /r/n";

              popupStr += "</html> /r/n";

              popupWin.document.write(popupStr);

              popupWin.focus();

              popupWin.txt.value = document.all[target].value;

         }

         catch(e)

         {

              // alert(e.message);

              popupWin.close();

              popupWin=null;

         }

     }

</script>

 

后台代码:

private void Page_Load(object sender, System.EventArgs e)

{

     if(!Page.IsPostBack)

     {

     btnEdit.Attributes.Add("onclick","Popup('txtTest','500','300','"+txtTest.MaxLength+"');");

     }

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值