用JAVASCRIPT从弹出的窗口中获取值

设三个页面:Father.aspx    SubOpen.aspx    SubModalDialog.aspx

 

 

在Father.aspx中:

 

<asp:Button ID="Button1" runat="server" Text="一般窗口" OnClientClick="openwin() />

<asp:Button ID="Button2" runat="server" Text="模态窗口"  OnClientClick="openmodalwin()"/>

 

<asp:TextBox ID="backvalue" runat="server"></asp:TextBox>

 

写JAVASCRIPT函数:

<script language="javascript">


   function openwin()
   {


   var 

 

 childwin=window.open ("Sub.aspx","1","height=400px,width=400px,top=400px,left=400px");


   childwin.Fvalue.value="一般窗口";


   }
   
   function openmodalwin()
   {


   window.param="模态窗口";


   var str=window.showModalDialog("Sub.aspx",window,"dialogtop:200px; 

 

   dialogleft:300px;status:no;help:no");


   if(str!=null)
   {


   document.getElementById("backvalue").value=str;

   }

   } 
   

   </script>

 

 

 

 

在SubOpen.aspx中:

 

        function backtowina()
        {
        window.opener.document.getElementById("backvalue").value=document.getElementById("Svalue").value;
        }

 

 

   传来的值:    <asp:TextBox ID="Fvalue" runat="server"></asp:TextBox>
   传回去的值:     <asp:TextBox ID="Svalue" runat="server"></asp:TextBox>
 <asp:Button ID="Button1" runat="server" Text="设定主页面值" OnClick="backtowina()" />

 

 

 

在SubModalDialog.aspx中:

   window.document.getElementById("Fvalue").value=window.dialogArguments.param;

 

    var parentwin=window.dialogArguments;


    function backtowinb()
    {


    parentwin.document.getElementById("backvalue").value=document.getElementById  

 

("Svalue").value;


    }

 

 

   传来的值:    <asp:TextBox ID="Fvalue" runat="server"></asp:TextBox>
   传回去的值:     <asp:TextBox ID="Svalue" runat="server"></asp:TextBox>
 <asp:Button ID="Button1" runat="server" Text="设定主页面值" OnClick="backtowinb()" />

 

 

 

 

 

 

最后在加一个小功能:鼠标经过GridView时行背景发生变化

 

在GridView1的RowDataBound事件里加以下代码就可以了

 

        if (e.Row.RowIndex > -1 && e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowType != DataControlRowType.Header)//鼠标在表头背景不变
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ccccff'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'");
            }
        }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值